string strOutPath="";
arrFilePath=myCommonMethod.UploadPic(Files,"/UpLoads/UpPicture/");
this.GetThumbnailImage(120,150,100,System.IO.Path.GetFileName(arrFilePath[0].ToString()) ,out strOutPath);
//生成缩略图函数
/// <summary>
///
/// </summary>
/// <param name="width">缩略图宽度</param>
/// <param name="height">缩略图高度</param>
/// <param name="level">缩略程度</param>
/// <param name="file_id">文件名称</param>
public void GetThumbnailImage(int width,int height,int level,string file_id,out string strOutParam)
{
string newfile= Request.PhysicalApplicationPath+"/UpLoads/UpPicture/"+"top_"+ file_id;
System.Drawing.Image oldimage = System.Drawing.Image.FromFile(Request.PhysicalApplicationPath+"/UpLoads/UpPicture/"+ file_id);
System.Drawing.Image thumbnailImage = oldimage.GetThumbnailImage(width, height,new System.Drawing.Image.GetThumbnailImageAbort(ThumbnailCallback), IntPtr.Zero);
Bitmap output=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(Encoder.Quality,(long)level);
output.Save(newfile,ici,ep);
//输出参数
strOutParam=newfile.Substring(newfile.LastIndexOf("/")+1);
//释放所有使用对象
ep.Dispose();
output.Dispose();
oldimage.Dispose();
thumbnailImage.Dispose();
// //删除源图片
// string file_path = "/UpLoads/UpPicture/"+"top_"+ file_id;
// usageIO.DeletePath(Request.PhysicalApplicationPath+"images/article_images/"+ file_id);
//// Response.Write("<script >parent.Form1.A_Simg.value ='"+file_path+"';location.replace('Upload_Img.aspx')</script>");
}
bool ThumbnailCallback()
{
return false;
}