Invisible HDC

  • Thread starter Thread starter Charles Teel
  • Start date Start date
C

Charles Teel

Is there a way to create an invisible HDC object, that I can using the
System.Drawing.Graphics class on, and then copy that data to a bitmap?

I've been able to do it with a visible HDC (a form), but I need to do
it with an invisible one and one that is larger that the device screen.
 
You can create a bitmap using:
Bitmap bmp = new Bitmap(width, height);

Then get the graphics object from the bitmap:
Graphics g = Graphics.FromImage(bmp);

Then you retrieve the DC handle:

IntPtr hDC = g.GetHdc();

Remember to dispose of the graphics object g and the bmp when you are done
with them.

Regards,
Rick D.
 
You can create a bitmap using:
Bitmap bmp = new Bitmap(width, height);

Then get the graphics object from the bitmap:
Graphics g = Graphics.FromImage(bmp);

Then you retrieve the DC handle:

IntPtr hDC = g.GetHdc();

Remember to dispose of the graphics object g and the bmp when you are done
with them.  

Regards,
Rick D.

The problem with that option is if the Bitmap gets to be too large,
you start getting OutOfMemoryExceptions. Many of the HDC's that I will
need are going to be in the 1000x1000 range and in some cases larger.
 
Back
Top