Cut an image and display the two parts that have been cut

Asked

Viewed 35 times

0

I’m starting in the programming and I came up with a question. I’m trying to cut an image in half and show in two picture box the two cuts.

Imagem Original

I’m making the cut like this.

private void Btn_Recortar_Click(object sender, EventArgs e)
{

Lobj_ImagemcortadaEsquerda = RecortarImagem(ImagemOriginalCopiada, 0, 0, 100, 60);
Lobj_ImagemCortadaDireita = RecortarImagem(ImagemOriginalCopiada, 0, 0, 200, 60);

pictureBox1.Image = Lobj_ImagemCortadaDireita;
pictureBox2.Image = Lobj_ImagemcortadaEsquerda;

pictureBox1.Image = Lobj_Imagemcortada2;
pictureBox2.Image = Lobj_Imagemcortada;
}

Cut-out method

public Bitmap RecortarImagem(Bitmap ImagemOriginal, int cropX, int cropY, int cropWidth, int cropHeight)
{
ImagemRecortada = true;

Rectangle rect = new Rectangle(cropX, cropY, cropWidth, cropHeight);
Bitmap cropped = ImagemOriginalCopiada.Clone(rect, ImagemOriginal.PixelFormat);
return cropped; 
}

The idea is to have two images. In the first pictureBox:

PictureBox1

and the second pictureBox:

inserir a descrição da imagem aqui

1 answer

0


You can get the original size before cutting.

int width = ImagemOriginalCopiada.Size.Width;
int height = ImagemOriginalCopiada.Size.Height;
Lobj_ImagemcortadaEsquerda = RecortarImagem(ImagemOriginalCopiada, 0, 0, width/2, height);
Lobj_ImagemCortadaDireita = RecortarImagem(ImagemOriginalCopiada, width / 2, 0, width/2, height);

pictureBox1.Image = Lobj_ImagemcortadaEsquerda;
pictureBox2.Image = Lobj_ImagemCortadaDireita;

Browser other questions tagged

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