I'm trying to cut out a separate part from my screen and save this as an png. But I dont know why my Image im getting is empty.
This is my function I use:
private void createImage(Point pointTL, Point pointRD)
{
Size size = new Size();
size.Width = pointRD.X - pointTL.X;
size.Height = pointRD.Y - pointTL.Y;
//Create a new bitmap.
var targetBitmap = new Bitmap(size.Width,
size.Height,
PixelFormat.Format32bppArgb);
Rectangle targetRectangle = new Rectangle(pointTL.X, pointTL.Y, size.Width, size.Height);
Rectangle sourceRectangle = new Rectangle(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
using(Bitmap sourceBitmap = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb))
using (Graphics g = Graphics.FromImage(targetBitmap))
g.DrawImage(sourceBitmap, targetRectangle, sourceRectangle, GraphicsUnit.Pixel);
if (pictureBoxScreenshot.Image != null)
{
pictureBoxScreenshot.Dispose();
pictureBoxScreenshot.Image = targetBitmap;
}
targetBitmap.Save("Screenshot.png", System.Drawing.Imaging.ImageFormat.Png);
}
So my Screenshot im getting looks like this. There is just nothing.