Printing in Delphi 2

Posted on 1997-08-01
Last Modified: 2010-04-04
I'm trying to print an image in a TImage component using an entire page.  How do I do this?
Question by:Evil
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
1 Comment

Accepted Solution

CyberWolf earned 50 total points
ID: 1340341
Hi Evil,

I think this will solve your problem. Even if it only works with bitmaps (probably the most common type of image you will use), you can use it for icons and metafiles too by converting them into bitmaps. You can do this using a temporary bitmap, and simply draw the contents of the TImage canvas on it. Then simply change the reference to the timage bitmap to your custom bitmap.

procedure TPrintBMPForm.Print1Click(Sender: TObject);
  Info: PBitmapInfo;
  InfoSize: Integer;
  Image: Pointer;
  ImageSize: DWORD;
  with Image1.Picture.Bitmap do
    { Call GetDIBSizes to get the Info header and image size }
    GetDIBSizes(Handle, InfoSize, ImageSize);
    { Allocate memory for the info header }
    Info := MemAlloc(InfoSize);
      { Allocate memory for the Image }
      Image := MemAlloc(ImageSize);
        { Retrieve the bitmap bits in device-independent format, the
          palette  adn the Info header }
        GetDIB(Handle, Palette, Info^, Image^);
        with Info^.bmiHeader do begin
        { Call StretchDIBits to print the bitmap }
            StretchDIBits(Printer.Canvas.Handle, 0, 0, Printer.PageWidth,
              Printer.PageHeight, 0, 0, biWidth, biHeight, Image, Info^,
              DIB_RGB_COLORS, SRCCOPY);
        FreeMem(Image, ImageSize); // Free the memory allocated
      FreeMem(Info, InfoSize);

I hope this will help you,

See ya,


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

Suggested Solutions

Title # Comments Views Activity
Delphi - replicating a form 8 92
Printing problem 2 110
Delphi: ForceDirectory plain function 7 50
Get monday of current week where a week always starts on monday 2 20
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

749 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