Solved

printing TBitmaps

Posted on 1998-08-01
9
403 Views
Last Modified: 2010-04-04
How do I print a TBitmap object without having to display it on a form and using CopyRect. I've tried using TBitmap.LoadFromFile and then using a Printer.Canvas.StretchDraw but all I get is a completely blank page
0
Comment
Question by:elkiors
[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
  • 6
  • 3
9 Comments
 
LVL 3

Expert Comment

by:Matvey
ID: 1359432
Look at Delpi\Source\VCL\Forms.PAS for TCustomForm.Print.

I see you want to stretch your bitmap above all the page, right? That will be something like this:

Var
  Info: PBitmapInfo;
  InfoSize: Integer;
  Image: Pointer;
  ImageSize: DWORD;
  DIBWidth, DIBHeight: Longint;
  bmp: TBitmap;
**********************************************
  GetDIBSizes(bmp.Handle, InfoSize, ImageSize);
  Info := AllocMem(InfoSize);
  Image := AllocMem(ImageSize);
  GetDIB(bmp.Handle, 0, Info^, Image^);
  with Info^.bmiHeader do
  begin
    DIBWidth := biWidth;
    DIBHeight := biHeight;
  end;
  With Printer Do
    StretchDIBits(Canvas.Handle, 0, 0, PageWidth, PageHeight,
                  0, 0, DIBWidth, DIBHeight, Image, Info^,
                  DIB_RGB_COLORS, SRCCOPY);
  FreeMem(Info, InfoSize);
  FreeMem(Image, ImageSize);

StretchDraw won't work because you give it Printer.PageWidth and Printer.PageHeight as a parameter, and they are actually 3000 pixels each for just a 300 DPI printer.

c u, Matvey
0
 

Author Comment

by:elkiors
ID: 1359433
For Matvey

This looks like it could be the answer. I can't believe how quickly you responded. Cheers ! Now, just give me a while to drop your code into my project to see what happens, afterall, I'm fairly new to this and I'm not sure just by looking at, what's going on. I can see you're messing with memory and pointer and stuff so I'm gonna need some time to digest it.

See ya soon
Elkiors.

0
 

Author Comment

by:elkiors
ID: 1359434
Matvey:
I hope you don't take it the wrong way. I didn't mean to REJECT your answer, I just need time to see.

If it works the points are yours

thanks again

0
Technology Partners: 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!

 

Author Comment

by:elkiors
ID: 1359435
For Matvey :

You are a god among men !

The code works great ... Now, if I can just maintain aspect ratio and get it in the centre of the page ....

Anyway the points are definately yours, if only I can work out how to give you them !!!

thanx

Elkiors.

0
 

Author Comment

by:elkiors
ID: 1359436
For Matvey:

I've had an idea, post a blank answer to the question and then I can pass the points on to you that way. You'll get another 'A' rating aswell.

Thanks again

Elkiors.

0
 
LVL 3

Accepted Solution

by:
Matvey earned 50 total points
ID: 1359437
Hi, glad it works.
What did you say about centering the image? It's not hard - just calculate the coordinates and put it there.

It will be something like

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

Need anything else?
Glad to help, Matvey
0
 

Author Comment

by:elkiors
ID: 1359438
Thanks again Matvey

I didn't mean to bother you for more answers, I was just thinking while I was typing, you've given some more ideas to follow up.

May I say this one thing and I think it applies to everyone.

If everyone cared as much as the people who are hanging around this site then the world would be definately a better place

Thanxs again

I just hope I can repay by helping someone else with a question at some point, although I think I have a fair way to go to be at the same level of genius as you lot.

Thanxs

Elkiors.

0
 
LVL 3

Expert Comment

by:Matvey
ID: 1359439
I'm sure you can find some questions you can help with to someone. There are lots of simple questions, I think this one was simple too. I just wrote this code not a long time ago so I recalled quickly. In fact I'll release a bit more enhanced component than TPrinter soon to the Delphi pages. It will mainly just fix some fonts problem. Want to know when it's released? -Post your email and I'll tell you...

c u on another thread!
0
 

Author Comment

by:elkiors
ID: 1359440
Hi Matvey,

It's sounds like you've got something good going. I'd certainly be interested to see it when it's released. Like I said earlier, I'm still only a novice but I picking up loads of ideas.

At the moment I'm working on a colour manager for bitmaps cos I think the colour manager in Corel 7 is crud to be mild. If I manage to finish it and get it working properly I see if I can get it posted up here somewhere.

Incidently, my username is a bit ambiguous, if anyone wants to talk directly you can find me at

darren.elkiors@mcmail.com

I really think this site's a great idea.

Thanx

elkiors. (darren)

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

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…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

710 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