最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時間:2007年09月10日 21:49:29   作者:  
bitmap.Save(imgPath,ImageFormat.Jpeg);  
//這是保存縮略圖的一段代碼,其中的ImageFormat.Jpeg一定不能省略,即使你保存的文件本來就是jpg格式的,也不能去掉。因?yàn)槿绻サ舻脑?,生成的縮略圖比原始圖片還要大!


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


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



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

相關(guān)文章

最新評論

台东市| 积石山| 赤壁市| 察隅县| 高阳县| 昌邑市| 河间市| 贵港市| 紫阳县| 连平县| 沙雅县| 广州市| 丹寨县| 新乐市| 瑞安市| 蒙阴县| 苗栗县| 霸州市| 扶余县| 饶河县| 宜丰县| 雅安市| 汉寿县| 衡阳县| 修武县| 芜湖县| 天长市| 库伦旗| 韩城市| 凤冈县| 临安市| 崇信县| 吉安市| 河南省| 宁晋县| 监利县| 泗水县| 株洲县| 临夏市| 辉南县| 桑植县|