================================命名空间======================
<%@ Page Language="C#" %>
<%@ Import Namespace ="System.Data" %>
<%@ Import Namespace =" System.IO" %>
<%@ Import Namespace ="System.Drawing.Imaging" %>
<%@ Import Namespace="System.Drawing" %>
================================保存函数======================
private void SavePic()
{
int width = 130;//缩略图的宽度
int height = 150;// 缩略图的高度
int level = 100; //缩略图的质量 1-100的范围
//被选择的原图路径
string strPicPath = fupBigPic.PostedFile.FileName;
string strFileName = DateTime.Now.ToString("yyyyMMddHHmmss")+"_大品牌汽车用品";
string extendName = System.IO.Path.GetExtension(fupBigPic.FileName);
try
{
System.Drawing.Image oldimage = System.Drawing.Image.FromFile(strPicPath);
System.Drawing.Image thumbnailImage = oldimage.GetThumbnailImage(width, height, new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero);
Bitmap bm = new Bitmap(thumbnailImage);
//处理JPG质量的函数
ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();
ImageCodecInfo ici = null;
foreach (ImageCodecInfo codec in codecs) { if (codec.MimeType == "image/jpeg")ici = codec; }
EncoderParameters ep = new EncoderParameters();
ep.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, (long)level);
//记下路径写到数据库
strBigPic = "../Manager/Upload/Product/" + strFileName + extendName;
fupBigPic.SaveAs(MapPath(strBigPic));
strSmallPic ="../Manager/Upload/Product/" + strFileName + "_Small" + extendName;
bm.Save(MapPath(strSmallPic), ici, ep);
}
catch
{
throw;
}
}
bool ThumbnailCallback()
{
return true;
}