Solved

Print Stretched image in specific canvas position

Posted on 2004-04-29
3
284 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
Comment Utility

 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
Comment Utility
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
Comment Utility
You may have some problems using PageWidth and PageHeight on some printers.
You should set some reasonable margins.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

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…
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…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

763 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

13 Experts available now in Live!

Get 1:1 Help Now