How to get part of an image and use it as a separate image?

I have a tile, but all the tiles are in the same image. I want to get each fragment as a raster image or an array of images. Is there any method that does this?

+6
source share
1 answer

Use Bitmap.Clone (Rectangle, PixelFormat) . Here we can set the PixelFormat of the new image and the size of the rectangle.

// Create a Bitmap object from a file. Bitmap myBitmap = new Bitmap("Grapes.jpg"); // Clone a portion of the Bitmap object. Rectangle cloneRect = new Rectangle(0, 0, 100, 100); System.Drawing.Imaging.PixelFormat format = myBitmap.PixelFormat; Bitmap cloneBitmap = myBitmap.Clone(cloneRect, format); // Draw the cloned portion of the Bitmap object. e.Graphics.DrawImage(cloneBitmap, 0, 0); 
+19
source

Source: https://habr.com/ru/post/896566/


All Articles