Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

printing TBitmaps

Posted on 1998-08-01
9
Medium Priority
?
414 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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 200 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

782 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