I need to take the print out of a win-form. This is the code i am using to capture and print the form:
public static extern long BitBlt (IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, int dwRop);
private Bitmap memoryImage;
private void CaptureScreen()
{
Graphics mygraphics = this.CreateGraphics();
Size s = this.Size;
memoryImage = new Bitmap(s.Width, s.Height, mygraphics);
Graphics memoryGraphics = Graphics.FromImage(memoryImage);
IntPtr dc1 = mygraphics.GetHdc();
IntPtr dc2 = memoryGraphics.GetHdc();
BitBlt(dc2, 0, 0, this.ClientRectangle.Width, this.ClientRectangle.Height, dc1, 0, 0, 13369376);
mygraphics.ReleaseHdc(dc1);
memoryGraphics.ReleaseHdc(dc2);
}
private void printDocument1_PrintPage(System.Object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawImage(memoryImage, 0, 0);
}
private void printButton_Click(System.Object sender, System.EventArgs e)
{
CaptureScreen();
printDocument1.Print();
}
But the problem is the printing quality I am getting is very low. The output is very blurred and hazy.
Plz help me to solve this out
Thanks in Advance...
HasanPosted Apr 10, 2008, 8:53 AM
Thanks for the answer. For solving my problem I want to save the captured image file in my harddrive first and then take the print out from the saved file. After taking the printout I want to delete the temporary image file from my harddrive.
Plz help me with the necessary code sample
Thanks again.....
Bechir BejaouiPosted Apr 10, 2008, 6:33 AM
stock you image in the buffer as a byte array then
you can retrive it using GetBuffer
MemoryStream myMStream = new MemoryStream();
byte[]Image = myMStream.GetBuffer();
it's more better
If you encounter a problem in performing this send me back a message