Solved

Printing in Delphi 2

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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 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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

860 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