private void Page_Load(object sender, System.EventArgs e)
{
ImgReduceCutOut(64,64,"1.jpg","2.jpg");
}
/// <summary>
/// 缩小裁剪图片
/// </summary>
/// <param name="int_Width">要缩小裁剪图片宽度</param>
/// <param name="int_Height">要缩小裁剪图片长度</param>
/// <param name="input_ImgUrl">要处理图片路径</param>
/// <param name="out_ImgUrl">处理完毕图片路径</param>
public void ImgReduceCutOut(int int_Width,int int_Height,string input_ImgUrl,string out_ImgUrl)
{
int CutOut_Width=0; // 裁剪的宽度
int CutOut_Height=0; // 裁剪的高度
int level = 100; //缩略图的质量 1-100的范围
CutOut_Width=int_Width;
CutOut_Height=int_Height;
System.Drawing.Image oldimage = System.Drawing.Image.FromFile(Server.MapPath(input_ImgUrl));
Bitmap bm=new Bitmap(oldimage);
ImageCodecInfo[] ImageCode=ImageCodecInfo.GetImageEncoders();
ImageCodecInfo ii=null;
foreach(ImageCodecInfo i in ImageCode)
{
if(i.MimeType=="image/jpeg") ii=i;
}
EncoderParameters ep=new EncoderParameters();
ep.Param[0]=new EncoderParameter(Encoder.Quality,(long)level);
Rectangle cloneRect = new Rectangle(20,20, CutOut_Width, CutOut_Height);
PixelFormat format = bm.PixelFormat;
Bitmap cloneBitmap = bm.Clone(cloneRect, format);
cloneBitmap.Save(Server.MapPath(out_ImgUrl),ii,ep);
}