asp.net圖片上傳生成縮略圖的注意事項
更新時間:2007年09月10日 21:49:29 作者:
bitmap.Save(imgPath,ImageFormat.Jpeg);
//這是保存縮略圖的一段代碼,其中的ImageFormat.Jpeg一定不能省略,即使你保存的文件本來就是jpg格式的,也不能去掉。因為如果去掉的話,生成的縮略圖比原始圖片還要大!
//另外,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)生的縮略圖質量奇差無比,不能使用!
//簡單代碼如下:
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);
//設定縮略圖呈現(xiàn)質量
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();
//這是保存縮略圖的一段代碼,其中的ImageFormat.Jpeg一定不能省略,即使你保存的文件本來就是jpg格式的,也不能去掉。因為如果去掉的話,生成的縮略圖比原始圖片還要大!
//另外,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)生的縮略圖質量奇差無比,不能使用!
//簡單代碼如下:
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);
//設定縮略圖呈現(xiàn)質量
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();
您可能感興趣的文章:
- ASP.NET簡單好用功能齊全圖片上傳工具類(水印、縮略圖、裁剪等)
- asp.net上傳圖片并作處理水印與縮略圖的實例代碼
- asp.net文件上傳功能(單文件,多文件,自定義生成縮略圖,水印)
- ASP.Net 上傳圖片并生成高清晰縮略圖
- asp.net 上傳圖片并同時生成縮略圖的代碼
- ASP.NET實現(xiàn)上傳圖片并生成縮略圖的方法
- Asp.net 文件上傳類(取得文件后綴名,保存文件,加入文字水印)
- asp.net 添加水印的代碼(已測試)
- asp.net下GDI+的一些常用應用(水印,文字,圓角處理)技巧
- asp.net如何在圖片上加水印文字具體實現(xiàn)
- asp.net實現(xiàn)生成縮略圖及給原始圖加水印的方法示例
相關文章
ASP.NET?MVC5網(wǎng)站開發(fā)之網(wǎng)站設置(九)
這篇文章主要為大家詳細介紹了ASP.NET?MVC5網(wǎng)站開發(fā)之網(wǎng)站設置,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2016-08-08
.NET 6實現(xiàn)基于JWT的Identity功能方法詳解
在.NET Web API開發(fā)中還有一個很重要的需求是關于身份認證和授權的。本文將介紹使用.NET框架自帶的認證和授權中間件去實現(xiàn)基于JWT的身份認證和授權功能的方法詳解,需要的可以參考一下2022-01-01
如何將數(shù)據(jù)綁到gridview然后導成excel
這篇文章主要介紹了如何將數(shù)據(jù)綁到gridview然后導成excel,需要的朋友可以參考下2014-02-02
.Net?Core?使用?TagProvider?與?Enricher?豐富日志的操作代碼
這篇文章主要介紹了.Net?Core?使用?TagProvider?與?Enricher?豐富日志的操作,本文通過示例代碼給大家介紹的非常詳細,需要的朋友可以參考下2024-03-03

