cropping an area from BitmapData with C#

后端 未结 5 1368
囚心锁ツ
囚心锁ツ 2020-12-17 23:28

I have a bitmap sourceImage.bmp

locking it\'s bits:

BitmapData dataOriginal = sourceImage.LockBits(new Rectangle(0, 0, sourceImage.W         


        
5条回答
  •  轮回少年
    2020-12-17 23:50

    You can try something like this:

    public static Bitmap CropBitmap(Bitmap bitmap, int x, int y, int w, int h)
    {
       Rectangle rect = new Rectangle(x, y, w, h);
       Bitmap cropped = bitmap.Clone(rect, bitmap.PixelFormat);
       return cropped;
    }
    

    And do something like this in yout code (sample):

    var croppedImagem = CropBitmap(dataOriginal, 0, 0, 100, 100); 
    

    I hope it helps!

提交回复
热议问题