Results 1 to 15 of 15

Thread: Qt Printing Good Image Quality.

  1. #1
    Join Date
    Jun 2008
    Location
    Rome, Italy
    Posts
    95
    Thanks
    19
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Qt Printing Good Image Quality.

    Hi to all,
    I'm having trouble printing an image inseted into a QTextDocument. The image has a 1900 dpi and the preview(Screenshot-1.png) looks good but printing it the resulting quality is poor(Screenshot-2.png).
    I'm attaching the project to allow you a test and give me a feedback.
    Thanks in advance, Danilo.
    Attached Files Attached Files

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Qt Printing Good Image Quality.

    Ehm, the image has a width of 387 pixel. Assuming 1900dpi this would result in about 5mm! Your code seems to be all right, but the image quality is too poor.

  3. #3
    Join Date
    Jun 2008
    Location
    Rome, Italy
    Posts
    95
    Thanks
    19
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt Printing Good Image Quality.

    The image is created by Inkscape, I scaled according to this formula DesignWidth = WantedWidth * 90 / WantedDpi.
    Any hints?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt Printing Good Image Quality.

    Why *90?

    If you want an image that is 1 inch wide and you want it to be 1900dpi then it has to be 1900 pixels wide. 387 pixels and 1900 dpi i 0.2'' which is about 4.9mm.


    BTW. Have you checked the actual resolution that the printer is set into when using QPrinter::HighResolution?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jun 2008
    Location
    Rome, Italy
    Posts
    95
    Thanks
    19
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt Printing Good Image Quality.

    Quote Originally Posted by wysota View Post
    Why *90?
    I've found this answer on an Inkscape forum:

    Your drawing in Inkscape must be 551,4x832,5 px so when you export it at 300dpi the size of the .png file will be 1838x2775px.
    the formula I used was a=1838*90/300=551,4
    so I scaled my drawing to 4.9mm in order to export an image of 387 pixels per 1900dpi. It has been an attempt to have a better result in printing. Before that I used to create my drawing with real size or rather as in that case a 387 pixels drawing at 90dpi. It's frustrating that the old software I'd like to replace has a better printing than I can do with Qt.

    Quote Originally Posted by wysota View Post
    BTW. Have you checked the actual resolution that the printer is set into when using QPrinter::HighResolution?
    Do you mean override the resolution with QPrinter::setResolution( int dpi )?

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt Printing Good Image Quality.

    I mean to print a line of known length and use a ruler to calculate its resolution.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Qt Printing Good Image Quality.

    So if you use Inkscape, then the easiest (= with no calculation of your own) would be to work with mm units while painting. In the export dialog you can then simply say what dpi you would like to have. By the way, scaling a svg only to export it perverts the whole purpose of vector drawing. Also please do not state that Qt has bad printing support, when it seems that you haven't understand the way Qt handle things.

    And about the 90: I guess that has to do with the screen resolution in combination with wysota's approach. (It is always an advantage to understand snippets something before c&p.)

  8. #8
    Join Date
    Jun 2008
    Location
    Rome, Italy
    Posts
    95
    Thanks
    19
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt Printing Good Image Quality.

    Quote Originally Posted by wysota View Post
    I mean to print a line of known length and use a ruler to calculate its resolution.
    So, I printed a line of 200 pixels using Paint.exe and, on the paper, his length was about 5,60 cm.
    The formula I used to calculate DPI is:

    DPI = (Pixels * 2,54) / Length expressed in cm

    resulted of 91dpi.

    Using a
    Qt Code:
    1. QPrinter printer(QPrinter::HighResolution);
    To copy to clipboard, switch view to plain text mode 
    then I got the printer.resolution(); of 600 an the resulting length of the same line was of 5,3 cm about 95dpi.

    Sorry but I don't get it!

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt Printing Good Image Quality.

    It means your printer prints with 90 dpi and not 1900dpi. Did you set it to 1900dpi? Did you use QPrintDialog for that?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  10. #10
    Join Date
    Jun 2008
    Location
    Rome, Italy
    Posts
    95
    Thanks
    19
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt Printing Good Image Quality.

    Quote Originally Posted by wysota View Post
    It means your printer prints with 90 dpi and not 1900dpi. Did you set it to 1900dpi? Did you use QPrintDialog for that?
    I didn't anything but use the project as it is.
    Here is the project with the different dpi images I tried an the SVG file too. I got the same poor result!
    PrintTest-1.zip

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt Printing Good Image Quality.

    The problem is not with the image but rather with your printer setup. Use QPrintDialog and set the printer resolution correctly. Your printer is set to 90 dpi so it will print in 90 dpi unless you tell it to print in higher resolution.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  12. #12
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Qt Printing Good Image Quality.

    Why *90?
    The magic number comes from the unit used in Inkscape SVG file coordinates: 1/90 inches (90 DPI). In the program these are the "px" unit. I don't know why they chose that unit rather than something more common like points, mm, or inches.
    Not saying it is relevant here, just where it came from.

    So, I printed a line of 200 pixels using Paint.exe and, on the paper, his length was about 5,60 cm.
    ...
    Sorry but I don't get it!
    Microsoft Paint has a notional pixel size of 1/90". You draw a line 200 pixels long and the program treats it as 200 * 1/90 = 2.22" (56.4mm).
    When Paint comes to print it it looks at the reported printer resolution and draws a number of printer pixels to give a line of 2.22". If the printer reports 300DPI (many lasers) then 667 printer pixels make up the line. If the printer reports 600DPI then it needs to draw 1333 printer pixels to span the 2.22" line on paper. (The 1/90" thickness of the line is 3 or 7 printer pixels respectively) The actual length of the line on paper should be close to invariant, but that depends on the invisible internals of Paint.

    When you take a raster image like the one in your first post scale it up to fit page width (essentially what you are doing with QTextDocument) each individual pixel in the original image is scaled up. You gave Qt 337 image pixels to stretch across the printer page. For a 200mm wide page each pixel gets scaled up to around 0.6x0.6mm. That is the finest detail that can be shown and leads to a jaggy appearance. If the printer reports 300DPI then the page has 2362 printer pixels across and each source image pixel is grown to be a block on the printed page of 7x7 pixels.

    To get "print quality" a raster image should be generated to have 300 pixels (or more) for every inch of physical size you want it to occupy on the printed page. For 200mm wide results the raster should be 200 / 25.4 * 300 = 2362 pixels across (approx). This can mean lots of large image files in a document.

    The limited scalability of raster images is part of the reason for the existence of vector formats in the first place. Can you show how you were using a an SVG that was giving poor results?

  13. #13
    Join Date
    Jun 2008
    Location
    Rome, Italy
    Posts
    95
    Thanks
    19
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt Printing Good Image Quality.

    Quote Originally Posted by ChrisW67 View Post
    ...
    The limited scalability of raster images is part of the reason for the existence of vector formats in the first place. Can you show how you were using a an SVG that was giving poor results?
    First of all, thanks for you explanation. The last attempt I've done was to use directly the svg (400 x 228 pixels) file in my QTextDocument as showed in the example project attached here.
    At the same time a dropped that svg file in firefox and printed it. The last was better! Try it!
    Attached Files Attached Files

  14. #14
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Qt Printing Good Image Quality.

    How did you create that SVG file? Did you convert it from PNG?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  15. #15
    Join Date
    Jun 2008
    Location
    Rome, Italy
    Posts
    95
    Thanks
    19
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Qt Printing Good Image Quality.

    Quote Originally Posted by wysota View Post
    How did you create that SVG file? Did you convert it from PNG?
    I created the SVG file using Inkscape. Just made a simple orange object and some text objects with Arial font. Then I turned the text objects into paths in order to avoid font's problem so one might visualize the drawing as pure vectorial group of objects. That's it. I often use Inkscape to make simple icons or logos.
    The PNG file is generated by exporting that drawing from Inkscape as well.
    Last edited by cydside; 12th August 2013 at 21:31.

Similar Threads

  1. Replies: 4
    Last Post: 11th August 2011, 11:31
  2. Image Quality when printing to PDF
    By JayMan8081 in forum Qt Programming
    Replies: 4
    Last Post: 25th August 2010, 18:19
  3. QGraphicsScene Low Image Quality
    By nemmartins in forum Qt Programming
    Replies: 2
    Last Post: 30th March 2010, 20:19
  4. Printing Screenshot -> poor quality
    By MarcSchubert in forum Qt Programming
    Replies: 2
    Last Post: 14th May 2007, 10:48
  5. Painter greyscale, image quality paint-brush!
    By patrik08 in forum Qt Programming
    Replies: 4
    Last Post: 22nd March 2007, 20:32

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.