Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

·Print TImage centered

Posted on 1999-07-19
19
Medium Priority
?
295 Views
Last Modified: 2010-04-06
Hi.. I have a TImage and want to print it centered in the paper.. how ?

thanx
0
Comment
Question by:bryan7
[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
  • 10
  • 7
  • 2
19 Comments
 
LVL 1

Expert Comment

by:m_adil
ID: 1389590
Hi bryan7
Try this

procedure PrintBmp;
var
   x,y:integer;
   bmp:TBitmap;
begin
bmp := TBitmap.Create;
bmp.Loadfromfile('c:\temp\test.bmp');

x := (Printer.PageHeight div 2) - (bmp.Height div 2);
y := (Printer.PageWidth div 2) - (bmp.Width div 2);

printer.BeginDoc;
printer.Canvas.Draw(y,x, bmp);
printer.EndDoc;

end;

0
 
LVL 2

Expert Comment

by:kjteng
ID: 1389591
The answer is definitely worth more than 15 points  - I think that is why no one has attempt to answer. In short, it is not that easy, read the following articles and you should be able to do it:

http://www.gnomehome.demon.nl/uddf/pages/printer.htm#printer3
0
 
LVL 1

Expert Comment

by:m_adil
ID: 1389592
Hi bryan7,
where are you...
Are you not interested in the soln.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Author Comment

by:bryan7
ID: 1389593
hi.. sorry for the delay..

m_adil.. it works..

kjteng.. m_adil answer works.. and he answered first..
I looked at the url u provided, and tried the code, but it give me errors.. like in "MemAlloc": Undeclared identifier.

thanx anyway.

m_adil, I'll be printing 640x480 and 480x600 images mostly.. and they appear very small in the paper.. can I easily stretch them to the double ? that would be enough.

thanx
0
 
LVL 2

Expert Comment

by:kjteng
ID: 1389594
1. Using m_adil solution will only centralise the image. However the image will be either too small or turn into blocks of squares if you stretch draw. That's why I have suggested the solution at uudf (which use DIB functions).

2. MemAlloc is only available in Delphi1. Change it To GetMem for other version.

3. There is another web site which contain sample code (both for D1 and D2, 3):
    http://www.efg2.com/Lab/OtherProjects/PrinterDemo1.htm
0
 
LVL 1

Expert Comment

by:m_adil
ID: 1389595
Yes you can stretch it to double using this code

procedure TForm1.PrintBmp;
var
  X, Y: Integer;
  bmp : TBitmap;
  Rect: TRect;
begin
  bmp := TBitmap.Create;
  bmp.LOADFROMFILE('c:\temp\test.bmp');

  X := (Printer.PageHeight div 2) - ((bmp.Height*2) div 2);
  Y := (Printer.PageWidth div 2) - ((bmp.Width*2) div 2);

  Rect.Top := x; Rect.Left := y;
  Rect.Right := y+ bmp.Width*2;
  Rect.Bottom := x + bmp.Height*2;

  Printer.BeginDoc;
  //printer.Canvas.Draw(y,x, bmp);
  Printer.Canvas.StretchDraw(Rect, bmp);
  Printer.EndDoc;

end;
0
 
LVL 1

Expert Comment

by:m_adil
ID: 1389596
Hi again disappeared....???
0
 
LVL 1

Expert Comment

by:m_adil
ID: 1389597
Hi
again disappeared....???
0
 
LVL 3

Author Comment

by:bryan7
ID: 1389598
no.. sorry,, I'm here.. I'm testing both systems..
0
 
LVL 1

Expert Comment

by:m_adil
ID: 1389599
Hi,
whats up....
have you tested the solns???
0
 
LVL 3

Author Comment

by:bryan7
ID: 1389600
hi.. yeah.. done..

I tried kjteng links, and tried the demos there, but can't see the quality difference..
thanx for the links anyway..

m_adil, your solution is quite easy and works fine for my needs..

0
 
LVL 3

Author Comment

by:bryan7
ID: 1389601
hi.. is it possible to print the pictures 4x in stead of 2x ?
with double size they fit well for a 800x600 pic,. but I'm mostly printing 640x480..


0
 
LVL 1

Expert Comment

by:m_adil
ID: 1389602
Yes you can print 4x pictures but the quality becomes poor as you increase the size.
To print 4x, instead of
Rect.Right := y+ bmp.Width*2;
Rect.Bottom := x + bmp.Height*2
try using
Rect.Right := y+ bmp.Width*4;
Rect.Bottom := x + bmp.Height*4

0
 
LVL 1

Expert Comment

by:m_adil
ID: 1389603
Hi bryan7,
Where have you been.........??????

0
 
LVL 3

Author Comment

by:bryan7
ID: 1389604
hi there.. sorry, haven't got much time..
i've checked it right now, it prints 4x.. but not centered :(
0
 
LVL 1

Expert Comment

by:m_adil
ID: 1389605
can you give me the code you used.
0
 
LVL 3

Author Comment

by:bryan7
ID: 1389606
procedure TView.HemisphereButton4Click(Sender: TObject);
var
    X, Y: Integer;
    bmp : TJpegImage;
    Rect: TRect;
begin
if Printer.Printing then
     Application.MessageBox('Printer is busy', 'Print Error', 0)
   else
 begin

    bmp := TJpegImage.Create;
    bmp.Loadfromfile(FileToLoad);

    X := (Printer.PageHeight div 2) - ((bmp.Height*2) div 2);
    Y := (Printer.PageWidth div 2) - ((bmp.Width*2) div 2);

    Rect.Top := x; Rect.Left := y;
    Rect.Right := y+ bmp.Width*4;
    Rect.Bottom := x + bmp.Height*4;

    Printer.BeginDoc;
    //printer.Canvas.Draw(y,x, bmp);
    Printer.Canvas.StretchDraw(Rect, bmp);

    bmp.Free;
    //    Printer.Copies:= 1;
    Printer.EndDoc;
  end;
end;

0
 
LVL 1

Accepted Solution

by:
m_adil earned 40 total points
ID: 1389607
OK, change
X := (Printer.PageHeight div 2) - ((bmp.Height * 2) div 2);
Y := (Printer.PageWidth div 2) - ((bmp.Width * 2) div 2);

to this
X := (Printer.PageHeight div 2) - ((bmp.Height * 4) div 2);
Y := (Printer.PageWidth div 2) - ((bmp.Width * 4) div 2);
0
 
LVL 3

Author Comment

by:bryan7
ID: 1389608
yep, thanks.. it worked perfectly..

bryan =)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

705 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