Drawing QImage to PDF-Document



  • Hi,

    I've some problems with the output of an QImage to a PDF-Document, here is the relevant program code:
    @QImage testbild("pic_47.bmp");
    QPrinter printer(QPrinter::ScreenResolution);
    printer.setOutputFormat(QPrinter::PdfFormat);
    printer.setColorMode(QPrinter::Color);
    printer.setOutputFileName(filename);
    printer.setPageSize(QPrinter::A0);
    printer.setOrientation(QPrinter::Portrait);

    QPainter painter(&printer);
    painter.drawImage(QPoint(0, 0), testbild);
    painter.end();
    @

    There seems to happen some kind of interpolation in the resulting output document (independed of ScreenResolution/HighResolution). However, if I prevent loading of the library qjpeg4.dll the output looks like my expectations. Though, I need the library qjpeg4.dll in this program. Adding lines like
    @
    ...
    painter.setWindow(0, 0, testbild.width(), testbild.height());
    painter.setViewport(0, 0, testbild.width(), testbild.height());
    painter.drawImage(QPoint(0, 0), testbild);
    @
    don't change the behaviour.

    At present the only alternative seems to be converting any pixel of the QImage into a QRect and drawing all of them with painter.drawRect(). However, this increase the size of the PDF-Document and needs more time for displaying.

    I would be happy for any suggestion.



  • Sounds like you have to resolve problems because of linking incompatible versions of libraries (like libjpeg). You tried to play around with LD_PRELOAD ?



  • The process explorer (I tried this under Windows XP) say there is no additional jpeg library, except qjpegd4.dll. Actually, in the example I don't use explicitly any jpeg functions. Presumably, Qt convert the QImage into a jpeg-bitmap for the PDF-Document.
    The Qt libraries are of course all of the same version (4.7.2) but I get this behavior with older versions, too.



  • Hmm... Windows and dlls.... Have you tried it on Ubuntu?



  • I just tried it under openSuse, the result is similar.

    I upload an example:
    !http://downloads.dyadic-computing.de/misc/Qt-Forum/example.png(Different results with/without jpeg library)!
    This are always small parts of the graphics, copied from the PDF and zoomed.



  • I have no clue what the problem could be. Maybe someone else knows. Maybe changing the render hints has an influence (QPainter::renderHints)?



  • From your four examples I would say that the jpeg quality is poor... What value are you using?
    It may just be that the default quality is low (maybe around 40-50 percents).



  • @unclewerner
    Default renderHints() is just QPainter::TextAntialiasing which should have no effect. I used some other values, but this has no effect.

    @Johan Solo
    The source in the example above is a bmp-bitmap, so there is no poor quality in the origin.
    Actually I use some kind of measurement values and convert them into a QImage for drawing, therefore there should be no interpolation and so on, like in the left figures above.



  • [quote author="DeVeL-2010" date="1304422450"]@Johan Solo
    The source in the example above is a bmp-bitmap, so there is no poor quality in the origin.
    Actually I use some kind of measurement values and convert them into a QImage for drawing, therefore there should be no interpolation and so on, like in the left figures above.[/quote]

    But you cannot store a bmp in a PDF, it's converted into jpeg when the PDF is created.

    Edit : png can also be used I think, but from I don't think it is the case in your example



  • [quote author="Johan Solo" date="1304426777"]
    But you cannot store a bmp in a PDF, it's converted into jpeg when the PDF is created.

    Edit : png can also be used I think, but from I don't think it is the case in your example[/quote]

    Well, even if my QImage is embedded as jpeg, how I can I get the result on the left side of the figures above, even if qjpeg4.dll is loaded? In other words, why is there a difference when qjpeg4.dll is loaded or not?



  • I cannot tell for sure, but it seems be that the default quality value in qjpeg4 is different from the one in the libjpeg (which is be used when you prevent qjpeg4 to be loaded).
    Unfortunately I cannot tell more, I'm not smart enough. Is there a way to select the jpeg quality created by qjpeg4 library?



  • I dig into the Qt sources and found in qprintengine_pdf.cpp the problem. If jpeg is in supportedImageFormats() the class QImageWrite ist used, otherwise an internal conversion happens (no other library like libjpeg is involved). My problem occur already in the QImageWrite conversion.

    Thanks for your help, now I understand the problem at least.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.