I generate a PDF document directly with a QPrinter (set to HighResolution) where I draw a few pixel images QImage, using QPainter::drawImage().
The images have a very small size (about 200x50 pixels) and have only 3 colors. I zoom them up in the PDF using a larger QRect as bounding box.
The QImage itself is not scaled.
I want the images clear and crisp in the PDF, however, they show scaling artifacts the same way as a bad jpg. (I want kind of png instead...).
How can I prevent this? Is it a question of QPainter or QPrinter? A question of image compression? Or is it the PDF viewer?
QImage* image;
//...
QPrinter printer(QPrinter::HighResolution);
printer.setOutputFileName("/home/xxx/test.pdf");
printer.setOutputFormat(QPrinter::PdfFormat);
QPainter painter;
painter.begin(&printer);
const int SCALING = 30;
QRect imageFrame = image->rect(); // <-- here comes my QImage
imageFrame.setSize( imageFrame.size() * SCALING );
painter.drawImage( imageFrame, *image );
//...
painter.end();
Edit: an example for clarification This is how the QImage looks on the screen:
When I put this image to a pdf, it appears like this, thus, with typical jpg artifacts. The bounding box of this image is enlarged to that the content can be seen in detail, but the used QImage is 1:1 (i.e. one of the text pixels is one pixel in the image).
When I scale the image itself up by 4 before putting it to the pdf (i.e. each text pixel is 4x4 pixels in QImage), it appears like this. Much closer to what I want, but with enlarged picture data and multiple file size.
My question is how I can use the original (small) QImage, which is shown with absolutlely crisp pixel squares in the PDF, without these artifacts.