Hi all,
I promised to get back to this question, and I found myself an answer:
g.CopyFromScreen(new Point(bounds.Left, bounds.Top), Point.Empty, bounds.Size, CopyPixelOperation.SourceCopy);
I just had to add the CopyPixelOperation.SourceCopy as last parameter to the CopyFromScreen method.
So the working code looks like this:
private void captureScreen()
{
try
{
Rectangle bounds = this.Bounds;
using (Bitmap bitmap = new Bitmap(bounds.Width, bounds.Height))
{
using (Graphics g = Graphics.FromImage(bitmap))
{
g.CopyFromScreen(new Point(bounds.Left, bounds.Top), Point.Empty, bounds.Size, CopyPixelOperation.SourceCopy);
}
bitmap.Save("C://Rectangle.bmp", ImageFormat.Bmp);
}
}
catch(Exception e)
{
MessageBox.Show(e.Message.ToString());
}
}
private void btnMenuExport_Click(object sender, EventArgs e)
{
captureScreen();
PdfDocument doc = new PdfDocument();
PdfPage oPage = new PdfPage();
doc.Pages.Add(oPage);
oPage.Rotate = 90;
XGraphics xgr = XGraphics.FromPdfPage(oPage);
XImage img = XImage.FromFile(@"C://Rectangle.bmp");
xgr.DrawImage(img, 0, 0);
doc.Save("C://RectangleDocument.pdf");
doc.Close();
}