Solved

printing TBitmaps

Posted on 1998-08-01
9
399 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
 

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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now