Solved

Printing in Delphi 2

Posted on 1997-08-01
1
194 Views
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?
0
Comment
Question by:Evil
1 Comment
 

Accepted Solution

by:
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);
var
  Info: PBitmapInfo;
  InfoSize: Integer;
  Image: Pointer;
  ImageSize: DWORD;
begin
  inherited;
  with Image1.Picture.Bitmap do
  begin
    { Call GetDIBSizes to get the Info header and image size }
    GetDIBSizes(Handle, InfoSize, ImageSize);
    { Allocate memory for the info header }
    Info := MemAlloc(InfoSize);
    try
      { Allocate memory for the Image }
      Image := MemAlloc(ImageSize);
      try
        { 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 }
          Printer.BeginDoc;
          try
            StretchDIBits(Printer.Canvas.Handle, 0, 0, Printer.PageWidth,
              Printer.PageHeight, 0, 0, biWidth, biHeight, Image, Info^,
              DIB_RGB_COLORS, SRCCOPY);
          finally
            Printer.EndDoc;
          end;
        end;
      finally
        FreeMem(Image, ImageSize); // Free the memory allocated
      end;
    finally
      FreeMem(Info, InfoSize);
    end;
  end;
end;



I hope this will help you,

See ya,

CyberWolf
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

708 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

19 Experts available now in Live!

Get 1:1 Help Now