Re: C# Printing Image with GDI

Tech-Archive recommends: Fix windows errors by optimizing your registry



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


.



Relevant Pages

  • Re: Graphics.GetHdc/Graphics.FromImage/R2_MASKPEN Woos
    ... graphics object passed to you from a bitmap and successfully create a useful ... GDI DC from it. ... > I do not have a bitmap to draw on, I have a Graphics object. ... > int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: GDI+ Performance for basic lines and fills
    ... graphics card and .NET GDI+ is a software only renderer. ... Find great Windows Forms articles in Windows Forms Tips and Tricks ... Answer those GDI+ questions with the GDI+ FAQ ... int height = 17; ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: Out of Memory Exception on DrawImage
    ... Answer those GDI+ questions with the GDI+ FAQ ... > indicating the memory problem in a asp.net app an not in a winforms app, ... >> regardless of the JPEG file size. ... >>> public static Image Crop(Image sourceImage, int x, int y, int width, ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: GDI+ Performance for basic lines and fills
    ... graphics card and .NET GDI+ is a software only renderer. ... Find great Windows Forms articles in Windows Forms Tips and Tricks ... Answer those GDI+ questions with the GDI+ FAQ ... int height = 17; ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: C# Printing Image with GDI
    ... What is BitPtr? ... public static int CopyBitmap(IntPtr HDC, int x, int y, int w, System.Drawing.Image Image) { ... you need to obtain a GDI memory device context from the Graphics object and use it as BitPtr. ...
    (microsoft.public.win32.programmer.gdi)