Re: C# Printing Image with GDI
- From: "Michael Phillips, Jr." <mphillips53@xxxxxxxxxxxxxxx>
- Date: Tue, 11 Sep 2007 11:31:10 -0400
if you know a "complete" solution for how to print an C# image to the
coordinates (y, x) with size (w, h) it would be great! i am trying around
for weeks :(
Graphics g = Graphics.FromImage( Image );
Is g valid? Is Ok returned by GetLastStatus()?
Why doesn't your solution work?
Does StretchBlt return FALSE? What does Marshal.GetLastWin32Error() return?
"Achim Bohmann" <a.bohmann@xxxxxx> wrote in message
news:%23LRISLI9HHA.4584@xxxxxxxxxxxxxxxxxxxxxxx
ok, i cutted out little too much...
Michael Phillips, Jr. wrote:
StretchBlt( hDestDC, x, y, w, h, BitPtr, 0, 0, Image.Width,
Image.Height, SRCCOPY );
What is BitPtr? What is the pixel format of the image that you trying
to Blt?
public static int CopyBitmap( IntPtr HDC, int x, int y, int w,
System.Drawing.Image Image) {
int h = w * Image.Height / Image.Width;
Graphics g = Graphics.FromImage( Image );
IntPtr BitPtr = g.GetHdc();
StretchBlt( hDestDC, x, y, w, h, BitPtr, 0, 0, Image.Width,
Image.Height, SRCCOPY );
g.ReleaseHdc( BitPtr );
return h;
}
if you know a "complete" solution for how to print an C# image to the
coordinates (y, x) with size (w, h) it would be great! i am trying around
for weeks :(
thanks in advance
Achim
System.Drawing.Image does not allow you to create a Graphics object from
an indexed bitmap.
Assuming your image is not indexed, then you need to create a Graphics
object from your source bitmap.
Once created, you need to obtain a GDI memory device context from the
Graphics object and use it as BitPtr.
Additionally, you should use SetStretchBltMode to specifiy the stretching
method to use. Try COLORONCOLOR.
After the call to StretchBlt, it is important to release the memory
device hdc obtained by the Graphics object.
"Achim Bohmann" <a.bohmann@xxxxxx> wrote in message
news:%237SrVJF9HHA.1208@xxxxxxxxxxxxxxxxxxxxxxx
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 (i also tried others...)
[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;
}
can someone see whats wrong???
thanks a lot!
Achim
.
- Follow-Ups:
- Re: C# Printing Image with GDI
- From: Achim Bohmann
- Re: C# Printing Image with GDI
- References:
- C# Printing Image with GDI
- From: Achim Bohmann
- Re: C# Printing Image with GDI
- From: Michael Phillips, Jr.
- Re: C# Printing Image with GDI
- From: Achim Bohmann
- C# Printing Image with GDI
- Prev by Date: Re: C# Printing Image with GDI
- Next by Date: Converting GDI+ Bitmap from unmanaged code to managed code
- Previous by thread: Re: C# Printing Image with GDI
- Next by thread: Re: C# Printing Image with GDI
- Index(es):
Relevant Pages
|