473,473 Members | 1,894 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Printing an Image using GDI

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
2 3740
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jody Gelowitz | last post by:
I am having a problem with printing selected pages. Actually, the problem isn't with printing selected pages as it is more to do with having blank pages print for those pages that have not been...
0
by: JF Turcotte | last post by:
Hi I'm unsuccessfully trying to print a form's image under VB.NET. To print under .NET is a real pain in the , I find it to be complex, lenghty, confusing, upsetting and ultimately not to be...
5
by: Senthil Kumar | last post by:
hi Group, Iam developing one Component in c#.It will load any kind of image either from Local machine or URL.Finally I do have options for printing and preview. While printing Iam facing the...
5
by: VMI | last post by:
I have a BMP image (the form is also in PDF) that contains a scanned copy of a paper form that we need to fill out. Is it possible to use this image in my application so that the application can...
3
by: D Witherspoon | last post by:
No matter what I do the default paper size is always either A3 or 11 by 8.5 .. Here is the code. Dim dlg As DialogResult pd.DocumentName = "Weld Image" Dim pkPaperSize As New...
1
by: hamil | last post by:
I am trying to print a graphic file (tif) and also use the PrintPreview control, the PageSetup control, and the Print dialog control. The code attached is a concatination of two examples taken out...
1
by: =?Utf-8?B?Q2hyaXM=?= | last post by:
Any tips on how to print the data in a datagridview control?
8
by: Neo Geshel | last post by:
Greetings. BACKGROUND: My sites are pure XHTML 1.1 with CSS 2.1 for markup. My pages are delivered as application/xhtml+xml for all non-MS web clients, and as text/xml for all MS web...
0
by: gnewsgroup | last post by:
In my asp.net 2.0 web application. I create chart images on the fly by getting the data from the database. These chart images all have fixed width, but the height is dynamic depending on the...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.