How to crop an image using C#?

后端 未结 14 1007
忘掉有多难
忘掉有多难 2020-11-22 05:16

How can I write an application that will crop images in C#?

14条回答
  •  温柔的废话
    2020-11-22 05:49

    Cropping an image is very easy in C#. However, doing the stuff how are you going to manage the cropping of your image will be a little harder.

    Sample below is the way how to crop an image in C#.

    var filename = @"c:\personal\images\horizon.png";
    var img = Image.FromFile(filename);
    var rect = new Rectangle(new Point(0, 0), img.Size);
    var cloned = new Bitmap(img).Clone(rect, img.PixelFormat);
    var bitmap = new Bitmap(cloned, new Size(50, 50));
    cloned.Dispose();
    

提交回复
热议问题