Thanks for your example, I am using the code provided by Erno, with some modifications, such as DrawRect instead of FillRect to draw the selected area.
However, I have some problems saving the selected area in JPG format. I use this code, but it seems that the Rect links are not suitable for this, I keep the neighboring area and not the exact location.
Does anyone have an idea on how to keep the exact location on a PictureBox image?
private void ButtonExport_Click(object sender, EventArgs e) { //exporter la sélection Bitmap bmp = new Bitmap(Rect.Size.Width,Rect.Size.Height); using (Graphics gr = Graphics.FromImage(bmp)) { gr.DrawImage(pictureBox1.Image, new Rectangle(0, 0, Rect.Size.Width, Rect.Size.Height), Rect, GraphicsUnit.Pixel); } bmp.Save(Directory.GetCurrentDirectory() + "\\Archives\\" + numFiche.ToString() + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg); }
Manuel lanon
source share