Solved

Printing in Delphi 2

Posted on 1997-08-01
1
201 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
[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
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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 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…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

734 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