2
Answers

How do I resize an image for preveiw in a pictue box.

Joe Smith

Joe Smith

17y
5.3k
1

How do I resize an image in a picture box. But only in the picture box, so that when I go to save the image it's still full size. here's an example of my code.

// If the user has chosen a path where to save the screenshot

if (saveScreenshot.ShowDialog() == DialogResult.OK)

{

// Hide the form so that it does not appear in the screenshot

this.Hide();

// Set the bitmap object to the size of the screen

bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);

// Create a graphics object from the bitmap

gfxScreenshot = Graphics.FromImage(bmpScreenshot);

// Take the screenshot from the upper left corner to the right bottom corner

gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);

this.imageDisplay.Image = bmpScreenshot;

// Save the screenshot to the specified path that the user has chosen

bmpScreenshot.Save(saveScreenshot.FileName, ImageFormat.Jpeg);

// Show the form again

this.Show();

}

 

Answers (2)