• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 358
  • Last Modified:

Printing bitmaps

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
gmayo
Asked:
gmayo
  • 3
  • 2
1 Solution
 
sgc_romaniaCommented:
try to use

PrintBitmap(CanvasHandle:  THandle; DestRect:  TRect;  Bitmap:  TBitmap);
0
 
kretzschmarCommented:
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
 
gmayoAuthor Commented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
kretzschmarCommented:
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
 
kretzschmarCommented:
hi geoff,

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

meikl ;-)
0
 
gmayoAuthor Commented:
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

Technology Partners: 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!

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now