Hello,
I hope someone can help me. I try to print an image and to draw a yellow rectangle with transparency, but it gives me a reading or writing protected memory error.
Here's the simplified code that reproduces the error:
private void PrintImage()
{
try
{
printDocument1.DocumentName = "Test";
printDocument1.PrintPage += new PrintPageEventHandler(printDocument1_PrintPage);
printDocument1.Print();
}
catch (Exception e)
{
//reading or writing protected memory error
}
}
private void printDocument1_PrintPage(object sender, PrintPageEventArgs e) {
if (!e.Cancel)
{
Image printImg = Bitmap.FromFile("d:\\temp\\img.gif"); //PRINT1
//Image printImg = new Bitmap(1096, 2200); //PRINT2
e.Graphics.DrawImage(printImg, 0, 0, 800, 1000);
SolidBrush b = new SolidBrush(Color.FromArgb(110, Color.Yellow)); //BRUSH 1
//SolidBrush b = new SolidBrush(Color.Yellow); //BRUSH 2
e.Graphics.FillRectangle(b, 50, 50, 100, 100);
e.HasMorePages = false;
}
else
e.Cancel = true;
}
If I call the function PrintImage () that causes the error.
If I replace the line PRINT1 by PRINT2
OR
if I replace the line BRUSH1 by BRUSH2
=
the print works.
Thank you for your help.
Guill