Help with printing
-
Hi
Please explain somebody how to print image with the 100% scale.
For example this code:
@
QPixemap pxm = .... //load image from file
QPrinter printer;
QPainter painter;
painter.begin(&printer);
double xscale = printer.pageRect().width()/double(pxm.width());
double yscale = printer.pageRect().height()/double(pxm.height());
double scale = qMin(xscale, yscale);
painter.scale(scale, scale);
painter.drawPixmap(0,0, pxm)
@Up-scale image (fit to page) to the page and this result isn't 100% image size.
If I remove this line:
@painter.scale(scale, scale);@The image will down-scale and this also isn't 100% image size.
I understand that printer operate in QPrinter::DevicePixel space and this is (usually) a much more than screen space.
My question is how to calculate relation between QPrinter::DevicePixel and Pixels for calculate correct scale coefficients.
Thanks. -
My current solution is:
@
QPainter painter;
painter.begin(&m_current_printer);const QPixmap& pxm = ///...pixmap from file
double prnDPI = m_current_printer.resolution();
//ANYBODY can explain me why 72 DOI is default dpi for the most popular image editors?
double inch_w = pxm.width() / 72.;
double inch_h = pxm.height() / 72.;double img_w_pix = inch_w * prnDPI;
double img_h_pix = inch_h * prnDPI;QRectF rc(0,0, img_w_pix, img_h_pix);
painter.drawPixmap(rc, pxm, QRectF(0,0, pxm.width(),pxm.height()));
@