C#图片裁剪与大小缩放

public Bitmap CutBitmap(Bitmap b, int left, int top, int Width, int Height)//对图片进行裁剪

{

Bitmap bm = b;

Graphics g = Graphics.FromImage(bm);

g.DrawImage(b, new Rectangle(0, 0, bm.Width, bm.Height), new Rectangle(left, top, Width, Height), GraphicsUnit.Pixel);

g.Dispose();

Bitmap bmp=ResizeBitmap(bm, 150, 150);

return bmp;

}

public Bitmap ResizeBitmap(Bitmap b, int dstWidth, int dstHeight)//对像片进行平滑缩放处理

{

Bitmap dstImage = new Bitmap(dstWidth, dstHeight);

System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(dstImage);

// 设置插值模式

g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.Bilinear;

// 设置平滑模式

g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

g.DrawImage(b,

new System.Drawing.Rectangle(0, 0, dstImage.Width, dstImage.Height),

new System.Drawing.Rectangle(0, 0, b.Width, b.Height),

System.Drawing.GraphicsUnit.Pixel);

g.Save();

g.Dispose();

return dstImage;

}