By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,186 Members | 1,545 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,186 IT Pros & Developers. It's quick & easy.

Printing an Image using GDI

P: n/a
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;
}
Aug 24 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
us**@domain.invalid wrote:
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
Aug 24 '07 #2

P: n/a
us**@domain.invalid wrote:
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
Aug 24 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.