PDA

View Full Version : Read DPI of QPixmap is it possible?



orlando
4th December 2009, 14:32
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!

fanat9
4th December 2009, 15:14
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?

orlando
7th December 2009, 01:01
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.

Gravis
7th December 2009, 02:19
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.

fanat9
7th December 2009, 15:53
What I meant is dpi is not properties of pixmap, but rather device you work with.

orlando
7th December 2009, 17:17
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)

wysota
7th December 2009, 18:21
Did you try QImage::textKeys() and QImage::text() ?

mhennings
18th November 2014, 14:18
@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.

^NyAw^
18th November 2014, 15:29
Have you looked how old is this post? :confused:

d_stranz
22nd November 2014, 02:06
It's probably a good thing that the poster averages only about 2 posts a year.