Solved

Print Stretched image in specific canvas position

Posted on 2004-04-29
3
287 Views
Last Modified: 2010-04-05
Brain freeze here.  Want to print a bitmap image to the printer canvas.  Using stretchdraw preserves the image's size, but prints in in the upper left hand corner of my doc.  Want to print it in the lower right hand corner (it's a barcode).  How can I print it there, and still keep it's original size?

thanks!

*** CODE BEGINS ***

  ScaleX, ScaleY: Integer;
  R: TRect;
begin
  with Printer do
  try
    ScaleX := GetDeviceCaps(Handle, logPixelsX) div PixelsPerInch;
    ScaleY := GetDeviceCaps(Handle, logPixelsY) div PixelsPerInch;
    R := Rect(0, 0, pBitmap.Width * ScaleX,
      pBitmap.Height * ScaleY);
    Canvas.StretchDraw(R, pBitMap);
  finally
    // nothing to do...yet
  end;

*** CODE ENDS ***
0
Comment
Question by:mitcht
  • 2
3 Comments
 
LVL 26

Expert Comment

by:Russell Libby
ID: 10955788

 ScaleX, ScaleY: Integer;
  R: TRect;
begin
  with Printer do
  try
    ScaleX := GetDeviceCaps(Handle, logPixelsX) div PixelsPerInch;
    ScaleY := GetDeviceCaps(Handle, logPixelsY) div PixelsPerInch;
    R := Rect(PageWidth-pBitmap.Width * ScaleX, PageHeight-pBitmap.Height * ScaleY, pBitmap.Width * ScaleX,
      pBitmap.Height * ScaleY);
    Canvas.StretchDraw(R, pBitMap);
  finally
    // nothing to do...yet
  end;


Regards,
Russell
0
 
LVL 26

Accepted Solution

by:
Russell Libby earned 125 total points
ID: 10955799
Sorry, slight mistake in the rect calculation....

 R:=Rect(PageWidth-pBitmap.Width * ScaleX, PageHeight-pBitmap.Height * ScaleY, PageWidth, PageHeight);

Russell

0
 
LVL 17

Expert Comment

by:mokule
ID: 10959207
You may have some problems using PageWidth and PageHeight on some printers.
You should set some reasonable margins.
0

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
Mydac connection data base issue 3 135
Delphi: how to send PJL commands to printer 3 88
Run video youtube webbrowse 10 57
Adoquery sql  left join does not work 25 80
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
A short film showing how OnPage and Connectwise integration works.
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

929 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

14 Experts available now in Live!

Get 1:1 Help Now