?
Solved

Printing bitmaps

Posted on 2003-11-17
6
Medium Priority
?
353 Views
Last Modified: 2010-08-05
Any ideas why I get a blank sheet of paper from this? Irrelevant parts of code removed for clarity.

PROCEDURE PrintBitmap(Canvas:  TCanvas; DestRect:  TRect;  Bitmap:  TBitmap);
  VAR
    BitmapHeader:  pBitmapInfo;
    BitmapImage :  POINTER;
    HeaderSize  :  DWORD;    // Use DWORD for D3-D5 compatibility
    ImageSize   :  DWORD;
BEGIN
  GetDIBSizes(Bitmap.Handle, HeaderSize, ImageSize);
  GetMem(BitmapHeader, HeaderSize);
  GetMem(BitmapImage,  ImageSize);
  TRY
    GetDIB(Bitmap.Handle, Bitmap.Palette, BitmapHeader^, BitmapImage^);
    StretchDIBits(Canvas.Handle,
                  DestRect.Left, DestRect.Top,     // Destination Origin
                                                      DestRect.Right  - DestRect.Left, // Destination Width
                  DestRect.Bottom - DestRect.Top,  // Destination Height
                  0, 0,                            // Source Origin
                  Bitmap.Width, Bitmap.Height,     // Source Width & Height
                  BitmapImage,
                  TBitmapInfo(BitmapHeader^),
                  DIB_RGB_COLORS,
                  SRCCOPY)
  FINALLY
    FreeMem(BitmapHeader);
    FreeMem(BitmapImage)
  END
END {PrintBitmap};

procedure TDebugForm.Button1Click(Sender: TObject);
var
      i, x, y : integer;
      bmp : TBitmap;
      dr, sr : TRect;
      col : TColor;
      prt : TPrinter;
begin
      bmp := TBitmap.Create;
      bmp.Width := 128 * 9 + 1;
      bmp.Height := 48 * 17 + 1;
      prt := Printer;
      prt.Orientation := poLandscape;
      prt.BeginDoc;

      for i := 1 to 8 do begin
            bmp.Canvas.Brush.Color := clSilver;
            bmp.Canvas.Pen.Color := clAqua;
            bmp.Canvas.Rectangle(0, 0, bmp.Width, bmp.Height);
            // more drawing stuff here
            bmp.SaveToFile('vw' + IntToStr(i) + '.bmp');

            SetRect(dr, 0, 0, prt.PageWidth, prt.PageHeight);
            if i > 1 then prt.NewPage;
            PrintBitmap(prt.Canvas, dr, bmp);
      end;
      prt.EndDoc;
end;

The bitmap is known to contain data, since it saves it to disk and I can load it in PaintShopPro. Drawing manually on the printer's canvas works fine (prt.Canvas.TextOut()).

NT4/D7Pro/EpsonC4000

Geoff M.
0
Comment
Question by:gmayo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 2

Expert Comment

by:sgc_romania
ID: 9764923
try to use

PrintBitmap(CanvasHandle:  THandle; DestRect:  TRect;  Bitmap:  TBitmap);
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 9764992
this may take no difference, sgc

just wondering about the complicated way
usualy i draw directly on the printer-canvas, with a bit ratio

but geoff will know why

looking later about the used api (guessing one parameter may not proper)

meikl ;-)
0
 
LVL 8

Author Comment

by:gmayo
ID: 9765477
SGC, if you look at the code, TCanvas is passed to the PrintBitmap routine, and the PrintBitmap routine uses Canvas.Handle in the call to StretchDIBits. So Meikl is right, it will make no difference.

Ordinary blits don't work (StretchDraw, CopyRect etc). Something to do with different devices (screen/printer I guess). It is documented (do a google for TPrinter and StretchDraw). The PrintBitmap routine was copied from one such site as a work-around to this problem. Why it doesn't work is beyond me.

Geoff M.

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 27

Expert Comment

by:kretzschmar
ID: 9765512
well, too late now here,
must now have a bit family-life,
but will take tomorrow a look about this problem,
if not soved until then

see you

meikl ;-)
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 750 total points
ID: 9770552
hi geoff,

tested your code -> works properly
seems to be a problem with your printer or device-driver

meikl ;-)
0
 
LVL 8

Author Comment

by:gmayo
ID: 9782538
It's beyond me this one. I guess I'll just have to do it manually. I'll give you the points on the basis that you did try it yourself.

Thanks

Geoff M.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month10 days, 11 hours left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question