How do you get a piece of an image?

Asked

Viewed 502 times

3

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

THEMED_CONTROL_BOX_WINDOWS_FIXED

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.
}

1 answer

2

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

The following example creates a Bitmap corresponding to the part defined by the rectangle whose upper left corner has as coordinates 0,0 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 your PictureBox.Image obtained as follows:
(I’m not sure if the cast is possible, but I believe.)

Bitmap myBitmap = (Bitmap)pictureBox1.Image;

or

Bitmap myBitmap = new Bitmap(pictureBox1.Image);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.