printing problem
-
Hi, When the print button is clicked, I save a snapshot of the screen to a bitmap file.
Graphics currentTab = this.CreateGraphics(); Size s = this.Size; Bitmap memoryImage = new Bitmap(s.Width - 10, s.Height - 36, currentTab); Graphics memoryGraphics = Graphics.FromImage(memoryImage); IntPtr dc1 = currentTab.GetHdc(); IntPtr dc2 = memoryGraphics.GetHdc(); BitBlt(dc2, 0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height, dc1, 2, 2, 13369376); CurrentPage = memoryImage; currentTab.ReleaseHdc(dc1); memoryGraphics.ReleaseHdc(dc2); CurrentPage.Save("sCurrentPage.bmp",System.Drawing.Imaging.ImageFormat.Bmp);
Then I start to do the printing.PrintDocument ppd = new PrintDocument(); PageSetupDialog pg = new PageSetupDialog(); printDialog1.Document = ppd; pg.Document = ppd; pg.PageSettings.Landscape = true; DialogResult result = printDialog1.ShowDialog(); if (result==DialogResult.OK) { ppd.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(PrintCurrentPage); ppd.Print(); } ppd.Dispose();
The first time I print, everything works ok. But if I hit the button again, I get an error, and the current screen doesn't save. (An unhandled exception of type 'System.Runtime.InteropServices.ExternalException' occurred in system.drawing.dll Additional information: A generic error occurred in GDI+.) If I comment out the printing part, the current page saves just fine. I also commented out just the lineppd.Print();
. The image saved fine and I didn't get any error messages. Any thoughts? Cheers, Mel -
Hi, When the print button is clicked, I save a snapshot of the screen to a bitmap file.
Graphics currentTab = this.CreateGraphics(); Size s = this.Size; Bitmap memoryImage = new Bitmap(s.Width - 10, s.Height - 36, currentTab); Graphics memoryGraphics = Graphics.FromImage(memoryImage); IntPtr dc1 = currentTab.GetHdc(); IntPtr dc2 = memoryGraphics.GetHdc(); BitBlt(dc2, 0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height, dc1, 2, 2, 13369376); CurrentPage = memoryImage; currentTab.ReleaseHdc(dc1); memoryGraphics.ReleaseHdc(dc2); CurrentPage.Save("sCurrentPage.bmp",System.Drawing.Imaging.ImageFormat.Bmp);
Then I start to do the printing.PrintDocument ppd = new PrintDocument(); PageSetupDialog pg = new PageSetupDialog(); printDialog1.Document = ppd; pg.Document = ppd; pg.PageSettings.Landscape = true; DialogResult result = printDialog1.ShowDialog(); if (result==DialogResult.OK) { ppd.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(PrintCurrentPage); ppd.Print(); } ppd.Dispose();
The first time I print, everything works ok. But if I hit the button again, I get an error, and the current screen doesn't save. (An unhandled exception of type 'System.Runtime.InteropServices.ExternalException' occurred in system.drawing.dll Additional information: A generic error occurred in GDI+.) If I comment out the printing part, the current page saves just fine. I also commented out just the lineppd.Print();
. The image saved fine and I didn't get any error messages. Any thoughts? Cheers, MelWhere is the function: 'BitBlt'? Is it a Win32 function or is it somewhere in the .Net Framework, or did you write it? I get "system.drawing.dll Additional information: A generic error occurred in GDI+" in any application when I try to save a Bitmap to the same file more than once. Try changing the name of this file after every save. Ex: First time name would be "sCurrentPage0.bmp" then "sCurrentPage1.bmp" "sCurrentPage2.bmp"...