Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Drawing QImage to PDF-Document
QtWS25 Last Chance

Drawing QImage to PDF-Document

Scheduled Pinned Locked Moved General and Desktop
12 Posts 3 Posters 10.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DeVeL-2010
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • frankcyblogic.deF Offline
      frankcyblogic.deF Offline
      frankcyblogic.de
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • D Offline
        D Offline
        DeVeL-2010
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • frankcyblogic.deF Offline
          frankcyblogic.deF Offline
          frankcyblogic.de
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • D Offline
            D Offline
            DeVeL-2010
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • frankcyblogic.deF Offline
              frankcyblogic.deF Offline
              frankcyblogic.de
              wrote on last edited by
              #6

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

              1 Reply Last reply
              0
              • JohanSoloJ Offline
                JohanSoloJ Offline
                JohanSolo
                wrote on last edited by
                #7

                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).

                `They did not know it was impossible, so they did it.'
                -- Mark Twain

                1 Reply Last reply
                0
                • D Offline
                  D Offline
                  DeVeL-2010
                  wrote on last edited by
                  #8

                  @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.

                  1 Reply Last reply
                  0
                  • JohanSoloJ Offline
                    JohanSoloJ Offline
                    JohanSolo
                    wrote on last edited by
                    #9

                    [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

                    `They did not know it was impossible, so they did it.'
                    -- Mark Twain

                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      DeVeL-2010
                      wrote on last edited by
                      #10

                      [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?

                      1 Reply Last reply
                      0
                      • JohanSoloJ Offline
                        JohanSoloJ Offline
                        JohanSolo
                        wrote on last edited by
                        #11

                        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?

                        `They did not know it was impossible, so they did it.'
                        -- Mark Twain

                        1 Reply Last reply
                        0
                        • D Offline
                          D Offline
                          DeVeL-2010
                          wrote on last edited by
                          #12

                          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.

                          1 Reply Last reply
                          0

                          • Login

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • Users
                          • Groups
                          • Search
                          • Get Qt Extensions
                          • Unsolved