Solved

Print Stretched image in specific canvas position

Posted on 2004-04-29
3
290 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

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…
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…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

785 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