Hi,
I'm encountering a problem using the PictureBox / Control.BackgroundImage. I'm trying to capture parts / entire screen using CopyFromScreen method. After capturing, I will print the Image onto the PictureBox.Image / Form's backgroundImage. I have succesfully captured the image and tested and by saving on a file. Now, my problem is that everytime I capture the Screen and print it out onto the PictureBox/ Form's Background Image, it prints out a big X, indicating the bitmap doesn't exist (afaik). I've tried using try catch method to catch necessary exceptions but nothing is being catched.
What possible solution on the problem?
Here's the code:
public partial class Form1 : Form
{
public Form1 ()
{
InitializeComponent ();
}
private void button1_Click (object sender, EventArgs e)
{
using (Bitmap capturedImage = new Bitmap (Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppRgb))
{
// Create a graphics object from the bitmap
using (Graphics gfx = Graphics.FromImage (capturedImage))
{
// Take the screenshot from the upper left corner to the right bottom corner
gfx.CopyFromScreen (Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
//capturedImage.Save ("sample.png", ImageFormat.Png);
//gfx.DrawImage (capturedImage, new Rectangle (0, 0, 100, 100));
//pictureBox1.Image = capturedImage;
}
pictureBox1.Image = capturedImage;
}
}
}
Thanks.