//另外,i " /> 国内激情视频在线观看,国产精品久久久久久久久久尿,欧美性猛交xxxx免费看漫画

色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

asp.net圖片上傳生成縮略圖的注意事項

bitmap.Save(imgPath,ImageFormat.Jpeg);  
//這是保存縮略圖的一段代碼,其中的ImageFormat.Jpeg一定不能省略,即使你保存的文件本來就是jpg格式的,也不能去掉。因為如果去掉的話,生成的縮略圖比原始圖片還要大!


//另外,imgPath必須首先創建,否則會產生GDI+的一般性錯誤。
path=System.Web.HttpContext.Current.Server.MapPath(path);
使用if(!System.IO.Directory.Exists(path))System.IO.Directiory.CreateDirectory(path); 


//生成縮略圖,不要使用GetThumbnailImage方法,這個方法產生的縮略圖質量奇差無比,不能使用!



//簡單代碼如下:
     string path=System.Web.HttpContext.Current.Server.MapPath(strpath);
      sourcePath=System.Web.HttpContext.Current.Server.MapPath(sourcePath);

      if(!System.IO.Directory.Exists(path))System.IO.Directory.CreateDirectory(path);

      string sourceImage =sourcePath + fileName;
      string thumbImage = path + fileName;

     //原圖(引用)
   Image img=Image.FromFile(sourceImage,true);

   //實際縮略圖大小
   System.Drawing.Size size=Pic.ImgSize(maxW,maxH,img.Width,img.Height);
   int w=size.Width;
   int h=size.Height;

   //繪制縮略圖
   Bitmap bitmap=new Bitmap(w,h);
   Graphics g=Graphics.FromImage(bitmap);

   //設定縮略圖呈現質量
   g.CompositingQuality=System.Drawing.Drawing2D.CompositingQuality.HighQuality;
   g.SmoothingMode=System.Drawing.Drawing2D.SmoothingMode.HighQuality;
   //g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;

   //清潔背景
   g.Clear(Color.White);

      Rectangle thumbRect=new Rectangle(0,0,w,h);
      g.DrawImage(img,thumbRect);

      //保存縮略圖
   bitmap.Save(thumbImage,ImageFormat.Jpeg);

   //釋放內存
   bitmap.Dispose();
   img.Dispose();
   g.Dispose();

AspNet技術asp.net圖片上傳生成縮略圖的注意事項,轉載需保留來源!

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

主站蜘蛛池模板: 太谷县| 茶陵县| 通许县| 万载县| 威海市| 齐河县| 邢台县| 皮山县| 碌曲县| 酒泉市| 合阳县| 鹤岗市| 连云港市| 门源| 漯河市| 红原县| 乐东| 海兴县| 南京市| 邯郸县| 玉环县| 阿尔山市| 德安县| 无为县| 长宁区| 丰镇市| 乌什县| 长汀县| 饶阳县| 松滋市| 广灵县| 郎溪县| 黔西| 金华市| 灵川县| 德保县| 贺兰县| 五华县| 凤阳县| 南阳市| 宁安市|