Using bitmaps witrh GDI

J

JoeB

Hi,

I need to load a bitmap resource an BitBlt it to a printer device context. I
cannot figure out how to do this. I would imagine that it is fairly simple
task, but i have no nolodge of device contexts that the whole this is
scaring me a little!

< im using the compact framework >

what i have:

Bitmap bm = new Bitmap(Utils.GetApplicationPath() + @"Bitmap1.bmp");
if( bm == null )
{
throw new Exception("Failed to load bitmap");
}
// load bitmap works ok.


// create working DC:
IntPtr TmpDC = GdiGraphics.CreateCompatibleDC( hPrinterDC );

// this fails, cannot convert 'bm' from Bitmap to IntPtr:
GdiGraphics.BitBlt( TmpDC, 0,0, bm.Width, bm.Height, bm, 0,0,
GdiGraphics.SRCCOPY );

Print( TmpDC );

GdiGraphics.DeleteObject( TmpDC );

GC.Collect(); // run garbage collection manually




Any ideas what im doing wrong??



TIA.


Joe
 
D

Dmytro Lapshyn [MVP]

Hi,

The IntPtr you need can be obtained by calling the GetHBitmap method on the
"bm" instance. I am not sure this method is supported in Compact Framework
though - MSDN seems to give no clear indication of that.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top