Page 1 of 1
TPrintPreview from a blob (bitmap) database field

Posted:
December 31st, 2005, 12:20 am
by danzman
Is there a way I can directly assign the bitmap field into PrintPreview? Can you show me some code?
thanks

Posted:
December 31st, 2005, 9:09 am
by Johnny_Bit
Gosh... It's in the examples... You just draw bitmap on page and that's all.

Posted:
December 31st, 2005, 1:33 pm
by danzman
What I am looking for is NOT dragging, it is something like this
TImage.picture.assign(DBImageField).
Can you tell me where in the samples is a statement similar to this?
Thanks
Gosh

Posted:
December 31st, 2005, 1:59 pm
by Kambiz
You have to provide the image before drawing it on the PrintPreview's canvas. As a simple solution, you can put an invisible DBImage on the form and use it for retrieving image from the database.
By the way, TPrintPreview is a low level printing tool, and you might not consider it as a report generator.

Posted:
December 31st, 2005, 3:00 pm
by danzman
I managed to create the DBImage and it works fine. Now I need to transfer this image to PrintPreview so that I can zoom, rotate and print the image. How do I do it from here?

Posted:
December 31st, 2005, 3:17 pm
by Kambiz
Now, DBImage1.Picture.Graphic contains the image, and you can use this property and one of PaintGraphic, PaintGraphcEx, or PaintGraphicEx2 methods of PrintPreview to draw the image on the PrintPreview's canvas.
Note: if DBImage1 has no image, DBImage1.Picture.Graphic could be nil. Therefore, you should check this condition otherwise you'll get an AV.

Posted:
December 31st, 2005, 3:38 pm
by danzman
I did something like this:
PrintPreview1.PaintGraphic(DbImage1.Width,DBImage1.Height,DBImage1.Picture.Graphic);
I got the runtime error: "Printer is not currently printing"
BTW, do I have the right X, Y values?

Posted:
December 31st, 2005, 9:03 pm
by Johnny_Bit
You must do everything like on a normal printer, so BeginDoc, EndDoc and so on.

Posted:
January 1st, 2006, 12:09 am
by Kambiz
X and Y are the picture coordinates on the canvas.

Posted:
January 2nd, 2006, 3:10 pm
by danzman
Hi Kambiz and Johnny - thanks for the help. I got it to work with your suggestions. For the benefit of others here is what I did -
(code snippet)
PrintPreview1.BeginDoc;
PrintPreview1.PaintGraphic(DbImage1.Picture.Width,DBImage1.Picture.Height,DBImage1.Picture.Graphic);
PrintPreview1.EndDoc;
Now All I need to do is to be able to zoom (resize), rotate and print the image. I know you will hear from me about this but let me do a little work and study your component a little more.
Thanks again

Posted:
January 3rd, 2006, 11:43 am
by Kambiz
DbImage1.Picture.Width and DBImage1.Picture.Height as X and Y parameters are wrong. PaintGraphic works like Draw method of a Canvas.
For resizing the image you can use PaintGraphicEx method instead of PaintGraphic. PaintGraphicEx works more or less like StretchDraw method of the canvas.
Please look at readme.htm for documentations.
TPrintPreview dosn't do anything with image rotation. You may use either
TRotateImage Component or
Image Work Package.