怎样把图片缩小上传到服务器

解决方案 »

  1.   

    图片先上传,再等比例缩放
    http://topic.csdn.net/u/20090927/12/c84daad0-1310-4d10-bdf8-77baacf652be.html
      

  2.   

            DirectoryInfo dir = new DirectoryInfo(Server.MapPath("~/admin/news"));
            FileInfo[] files = dir.GetFiles();        foreach (FileInfo f in files)
            {
                if (f.Name.ToLower() == "thumbs.db")
                    continue;            try
                {
                    string name = f.Name.Substring(0,f.Name.LastIndexOf("."));
                    string extension = f.Name.Substring(f.Name.LastIndexOf(".") + 1);                System.Drawing.Image img = System.Drawing.Image.FromFile(Server.MapPath("~/admin/news/") + f.Name);
                    
                    float scale = 250.0f / Math.Max(img.Width, img.Height);
                    int width = Convert.ToInt32(img.Width * scale);
                    int height = Convert.ToInt32(img.Height * scale);
                    System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(width, height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                    bmp.SetResolution(img.HorizontalResolution, img.VerticalResolution);
                    
                    System.Drawing.Image newImage = bmp.GetThumbnailImage(width, height, null, IntPtr.Zero);
                    newImage.Save(Server.MapPath("~/admin/news/thumbs/") + name + "." + extension,System.Drawing.Imaging.ImageFormat.Jpeg);
                }
                catch (Exception ex)
                {
                    Response.Write(ex.Message + "<br>");
                }
            }
      

  3.   

    drawing这个类应该可以找到相关方法试试看!