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
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Sending Gmail through Delphi 3 91
Create a path if not exists 7 69
Need Help Delphi 2010 CheckBox1 Stored value in memo 13 57
Adoquery sql  left join does not work 25 80
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…
Both in life and business – not all partnerships are created equal. As the demand for cloud services increases, so do the number of self-proclaimed cloud partners. Asking the right questions up front in the partnership, will enable both parties …

867 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now