Solved

printing TBitmaps

Posted on 1998-08-01
9
401 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
  • 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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Send message from delphi to whatsapp, is it possible? 3 1,465
LAN or WAN ? 11 92
Delphi Yen format 3 35
CheckListBox usage 3 59
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…
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…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

832 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