[Qt-interest] create image and print it
Oliver.Knoll at comit.ch
Oliver.Knoll at comit.ch
Thu Dec 3 09:48:20 CET 2009
Riccardo Roasio wrote on Wednesday, December 02, 2009 6:05 PM:
> ...
> I' trying using this piece of code but there are problems on
> resizing
*what* resizing? I don't see any call to QImage::scale() or the like, nor are you setting up any transformation matrix!
> ...the image is not resized during printing process...
Because you don't resize it:
> QPainter *painter = new QPainter(printer);
> painter->drawImage(0,0,*image,0,0,-1,-1,Qt::AutoColor);
> painter->setRenderHint(QPainter::Antialiasing,true);
> painter->end();
Checkout
* http://doc.trolltech.com/4.6/qimage.html#scaled and/or
* http://doc.trolltech.com/4.6/qpainter.html#setTransform
General info: http://doc.trolltech.com/4.6/painting-transformations.html
Then decide for your preferred printer resolution (150 DPI, 300 DPI, ...), set it with http://doc.trolltech.com/4.6/qprinter.html#setResolution, do a bit of math (think of your desired image size im mm or inch, do a little bit of "pixel to mm, using given DPI" magic math and you're done ;)
Now after a closer look at the method which you are calling:
painter->drawImage(0,0,*image,0,0,-1,-1,Qt::AutoColor);
It seems that you are calling http://doc.trolltech.com/4.6/qpainter.html#drawImage-9, which is usually used to draw only a *part* of the 'image'! From the docs: "The default, (0, 0) (and negative) means all the way to the bottom-right of the image." I guess you did misunderstand this part: it means that the *entire* (from your top-left [0, 0] point) source 'image' is drawn (and not just a part of it), *not* that it fills up the entire viewport or whatever!
Try using the simpler http://doc.trolltech.com/4.6/qpainter.html#drawImage-8 - there your only task would be to specify the target 'rectangle' (1st parameter) such that it covers the entire A4 page (or whatever size you desire), given the printer resolution (in DPI) and viewport (paper size). Qt then scales the image for you automagically ;)
Cheers, Oliver
--
Oliver Knoll
Dipl. Informatik-Ing. ETH
COMIT AG - ++41 79 520 95 22
More information about the Qt-interest-old
mailing list