Printing an Image using GDI

U

user

Hi all...

i am trying to print an image using GDI - but the only thing i get is a
black rectangle.

Does anybody know what is wrong, or how else to get the bitmap on the
printer (GDI+ is not possible. it is a POS printer (for restaurants) and
the printer internal fonts are a MUST for printing speed. as far as i
know printer internal fonts are only accessable through GDI, so all my
printing is GDI up to now)

the relevant code pieces:

first of all i import StretchBlt from gdi32.dll

[DllImport( "gdi32", CharSet = CharSet.Auto )]
private static extern bool StretchBlt( IntPtr hdcDest, int
xDest, int yDest, int wDest, int hDest, IntPtr hdcSrc, int xSrc, int
ySrc, int wSrc, int hSrc, int RasterOperation );


within my class i define the CopyBitmap Method

public static int CopyBitmap( IntPtr HDC, int x, int y, int w,
System.Drawing.Image Image) {
int h = w * Image.Height / Image.Width;
StretchBlt( hDestDC, x, y, w, h, BitPtr, 0, 0, Image.Width,
Image.Height, SRCCOPY );
return h;
}


and from another class i use this method

Image notiz = ...// load the image
if( notiz != null ) {
int w = m_RightMargin;
line += Win32Util.CopyBitmap( hdc, 0, line, w, notiz );
notiz.Dispose();
notiz = null;
}
 
A

Achim Bohmann

Hi all...

i am trying to print an image using GDI - but the only thing i get is a
black rectangle.

Does anybody know what is wrong, or how else to get the bitmap on the
printer (GDI+ is not possible. it is a POS printer (for restaurants) and
the printer internal fonts are a MUST for printing speed. as far as i
know printer internal fonts are only accessable through GDI, so all my
printing is GDI up to now)

the relevant code pieces:

first of all i import StretchBlt from gdi32.dll

[DllImport( "gdi32", CharSet = CharSet.Auto )]
private static extern bool StretchBlt( IntPtr hdcDest, int
xDest, int yDest, int wDest, int hDest, IntPtr hdcSrc, int xSrc, int
ySrc, int wSrc, int hSrc, int RasterOperation );


within my class i define the CopyBitmap Method

public static int CopyBitmap( IntPtr HDC, int x, int y, int w,
System.Drawing.Image Image) {
int h = w * Image.Height / Image.Width;
StretchBlt( hDestDC, x, y, w, h, BitPtr, 0, 0, Image.Width,
Image.Height, SRCCOPY );
return h;
}


and from another class i use this method

Image notiz = ...// load the image
if( notiz != null ) {
int w = m_RightMargin;
line += Win32Util.CopyBitmap( hdc, 0, line, w, notiz );
notiz.Dispose();
notiz = null;
}

.... me again - with news account settings done ;)

thanks in advance
Achim
 
P

Peter Duniho

Hi all...

i am trying to print an image using GDI - but the only thing i get is a
black rectangle.

Maybe a silly question, but...have you verified that the printer is
capable of handling StretchBlt? Call GetDeviceCaps and check for
RC_STRETCHBLT.

I ask because in "the olden days", some printer drivers simply didn't
support StretchBlt. You had to use StretchBlt on a memory bitmap and
then call BitBlt to get the bitmap to the printer.

I'd think in these modern times, GDI would just do the translation for
you if the driver doesn't support RC_STRETCHBLT, but maybe not.

Now, all that said, your question is pretty much off-topic here in the
C# newsgroup. You are likely to find more specific advice posting to a
newsgroup that is more specific to GDI and/or Windows printing.

Pete
 

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