//另外,i " /> 色综合色综合久久综合频道88,亚洲精品欧美一区二区三区,香蕉久久aⅴ一区二区三区

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

asp.net圖片上傳生成縮略圖的注意事項(xiàng)

bitmap.Save(imgPath,ImageFormat.Jpeg);  
//這是保存縮略圖的一段代碼,其中的ImageFormat.Jpeg一定不能省略,即使你保存的文件本來(lái)就是jpg格式的,也不能去掉。因?yàn)槿绻サ舻脑挘傻目s略圖比原始圖片還要大!


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


//生成縮略圖,不要使用GetThumbnailImage方法,這個(gè)方法產(chǎn)生的縮略圖質(zhì)量奇差無(wú)比,不能使用!



//簡(jiǎn)單代碼如下:
     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);

   //實(shí)際縮略圖大小
   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);

   //設(shè)定縮略圖呈現(xiàn)質(zhì)量
   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);

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

AspNet技術(shù)asp.net圖片上傳生成縮略圖的注意事項(xiàng),轉(zhuǎn)載需保留來(lái)源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 阿巴嘎旗| 黔南| 安平县| 湘西| 松滋市| 长治县| 禹城市| 岳池县| 连南| 荣成市| 冀州市| 靖远县| 宜川县| 图们市| 宣威市| 无棣县| 泸水县| 新余市| 东丽区| 崇左市| 永清县| 永春县| 资溪县| 宁强县| 禄丰县| 平安县| 无极县| 稷山县| 都兰县| 泾阳县| 米易县| 仙游县| 庆安县| 肃宁县| 永善县| 宁明县| 丹棱县| 和田县| 锦屏县| 额尔古纳市| 高要市|