图片裁剪1

c#实现图片裁剪,输入由起点坐标x、y,宽度width、高度height组成的Rectangle

测试代码

static void Main()
{
    Bitmap b = file2img("test.jpg");
    Bitmap bb = img_tailor(b,new Rectangle(50,50,50,50)); img2file(bb, "test1.jpg"); }

图片裁剪函数

public static Bitmap img_tailor(Bitmap src, Rectangle range)
{
    return src.Clone(range, System.Drawing.Imaging.PixelFormat.DontCare);
}

图片读取和存储函数

//图片读取
public static Bitmap file2img(string filepath) { Bitmap b = new Bitmap(filepath); return b; } //图片生成 public static void img2file(Bitmap b, string filepath) { b.Save(filepath); }

猜你喜欢

转载自www.cnblogs.com/zhangyao-950907/p/9264825.html