How do I get a part of an image?

3

Based on this image as would be the code to separate into, as if it were sub image without dividing this image into different files:


Ex:

void splitImage(int numeroDeDivisoes, ref Image original, out Image[] final){
// aqui seria que nem essa imagem acima sendo dividida em Rectangle sem dividir o arquivo.
}
    
asked by anonymous 20.04.2015 / 14:26

1 answer

2

You can use the Clone method of the System.Drawing.Bitmap .

The following example creates a Bitmap corresponding to the part defined by the rectangle whose upper left corner has as 0,0 coordinates with a length and width equal to 100:

Rectangle cloneRect = new Rectangle(0, 0, 100, 100);
System.Drawing.Imaging.PixelFormat format = myBitmap.PixelFormat;
Bitmap cloneBitmap = myBitmap.Clone(cloneRect, format);

In the present case myBitmap is its PictureBox.Image obtained as follows:
(I'm not sure if cast is possible, but I think so.)

Bitmap myBitmap = (Bitmap)pictureBox1.Image;

or

Bitmap myBitmap = new Bitmap(pictureBox1.Image);
    
20.04.2015 / 15:17