Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

After panning an image in a picture box, how to save only the visible image

I have a C# program where I am displaying a pictureBox of size 600x450. I have an image of a higher resolution that I am displaying in this window. After I pan the image, I want to save only the visible picture in the window. When I use pictureBox.Image.Save(...), it saves the whole picture, not just the visual portion? How can I do this?

like image 374
Radhakrishnan Avatar asked Dec 05 '25 05:12

Radhakrishnan


1 Answers

Try to use this.

using (Bitmap bitmap = new Bitmap(YourPictureBox.ClientSize.Width,
                               YourPictureBox.ClientSize.Height))
{
   YourPictureBox.DrawToBitmap(bitmap, YourPictureBox.ClientRectangle);
   bitmap.Save(yourfilename, ImageFormat.Png);
}
like image 99
Litisqe Kumar Avatar answered Dec 07 '25 19:12

Litisqe Kumar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!