Solved

printing TBitmaps

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

 

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
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.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Suggested Courses
Course of the Month4 days, 8 hours left to enroll

636 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