Results 1 to 10 of 10

Thread: Read DPI of QPixmap is it possible?

  1. #1
    Join Date
    Oct 2009
    Posts
    3
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Read DPI of QPixmap is it possible?

    Hi,

    I have a "simple" question, is any way I can read an image DPI (Dots Per Inch) from a QPixmap?

    I have the following problem:
    - I want a user selects an image from his computer.
    - The system display that image on a QGraphicsPixmapItem on a QGraphicsScene.
    - The image then may be printed.

    Everything is ok, about that, but I need to read the Image DPI, so I can know the pixels to inches transformation (the printed image size).

    For example:
    If a have an image of 300 DPI and the image width is 2480px (pixels). Then I know that mi image is 8,26" (inches) width (2480/300 = 8,26).

    If I know the image DPI, then I can know how to scale the image to the proper scene scale.

    I've been searching about this, but I couldn't find anything.

    Thank you!

  2. #2
    Join Date
    Jan 2006
    Location
    Boston, MA
    Posts
    40
    Thanks
    1
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Read DPI of QPixmap is it possible?

    dpi for pixmap... does it make sense at all?
    You can scan a print with any resolution and you got a image in pixels. Then can print your image with resolution different from initial print.

    For example lets say you scanning 9" image with 100dpi - you will have 900pixels image. But later you can print again on printer with 900dpi or 300dpi with print size of 1" and 3". So what's the dpi value for an image?

  3. #3
    Join Date
    Oct 2009
    Posts
    3
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Read DPI of QPixmap is it possible?

    Quote Originally Posted by fanat9 View Post
    dpi for pixmap... does it make sense at all?
    You can scan a print with any resolution and you got a image in pixels. Then can print your image with resolution different from initial print.

    For example lets say you scanning 9" image with 100dpi - you will have 900pixels image. But later you can print again on printer with 900dpi or 300dpi with print size of 1" and 3". So what's the dpi value for an image?
    Thanks fanat9!

    So you mean that Fireworks and Photoshop are wrong? I mean, they use the image DPI to represent the print size of the image you are working with (on screen). I need to do something similar to that, represent the image on screen (I don't care the resolution of the printer right now).

    What you are saying is right, the scanning and printing, but I need to know if there is a way I can read the DPI, so I can do a preview on screen (and that size is the one the user wants). Then when I print the image, I will rescale it (I must mantain the size, not the dpi)

    Thank you again for answering.

  4. #4
    Join Date
    Aug 2009
    Location
    LOL Land
    Posts
    9
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Read DPI of QPixmap is it possible?

    Quote Originally Posted by orlando View Post
    Hi,

    I have a "simple" question, is any way I can read an image DPI (Dots Per Inch) from a QPixmap?

    I have the following problem:
    - I want a user selects an image from his computer.
    - The system display that image on a QGraphicsPixmapItem on a QGraphicsScene.
    - The image then may be printed.

    Everything is ok, about that, but I need to read the Image DPI, so I can know the pixels to inches transformation (the printed image size).

    For example:
    If a have an image of 300 DPI and the image width is 2480px (pixels). Then I know that mi image is 8,26" (inches) width (2480/300 = 8,26).

    If I know the image DPI, then I can know how to scale the image to the proper scene scale.

    the printer DPI can be obtained using QPrinter::resolution()
    the screen DPI can be obtained using QPaintDevice::physicalDpiX() and QPaintDevice::physicalDpiY()

    you can use these values to scale your image to make it look the same size on the screen as it will be printed out.

  5. #5
    Join Date
    Jan 2006
    Location
    Boston, MA
    Posts
    40
    Thanks
    1
    Thanked 6 Times in 6 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Read DPI of QPixmap is it possible?

    What I meant is dpi is not properties of pixmap, but rather device you work with.

  6. #6
    Join Date
    Oct 2009
    Posts
    3
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Read DPI of QPixmap is it possible?

    Thank you fanat9 and Gravis!

    I totally agree with you both, but (I always have a but, hehe) some image formats, like PNG (I think that tiff and jpeg too) store a byte with the image DPI (I know it's not a real image property, because it depends on the device).

    For example, if you do a PNG image with Fireworks, it store the dpi you choose for that image in the image file. So, when Fireworks, open the file again, can "translate" pixels to, for example, inches.

    I agree that it all depends on the device, and not on the image, but I know some image format has that information embedded. I think the best would be to open the file, as binary, read that information from the image file.

    Thank you again for the answers!! (and of course, you time)

  7. #7
    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: Read DPI of QPixmap is it possible?

    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.


  8. #8
    Join Date
    Dec 2012
    Posts
    7
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Read DPI of QPixmap is it possible?

    @wysota:
    This doesn't contain anything for a regular JPEG.

    @orlando:
    You have been misunderstood. The DPI you need is the information from acquiring the image. If you scan a ruler and want it printed out in the same scale, you need to know the DPI of the scanner / camera and the printer.
    The information probably is stored in the metadata of your image file (EXIF or similar).
    I know of no Qt function to retrieve this information.

  9. #9
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Read DPI of QPixmap is it possible?

    Have you looked how old is this post?
    Òscar Llarch i Galán

  10. #10
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,229
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Read DPI of QPixmap is it possible?

    It's probably a good thing that the poster averages only about 2 posts a year.

Similar Threads

  1. Position in a QPixMap created from a QGraphicsScene
    By stevel in forum Qt Programming
    Replies: 8
    Last Post: 8th April 2009, 23:39
  2. External Lib read from QBuffer on Calback problem
    By patrik08 in forum Qt Programming
    Replies: 2
    Last Post: 2nd June 2008, 20:43
  3. How to read CD with read?
    By vishal.chauhan in forum Qt Programming
    Replies: 6
    Last Post: 29th June 2007, 09:20
  4. QIODevice read()
    By ShaChris23 in forum Newbie
    Replies: 1
    Last Post: 3rd May 2007, 01:29
  5. QPixmap and HBITMAP
    By ToddAtWSU in forum Qt Programming
    Replies: 1
    Last Post: 21st June 2006, 17:24

Tags for this Thread

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.