PDA

View Full Version : how to get dimensions of image file inside a QDir.



toglia3d
29th September 2010, 23:37
Does anybody know how would I get the dimensions of an image file without loading it. Basically I want to list every "*.png" file of a specific folder showing its name and dimension.

I know I could do a QPixmap("path"), and get it that way, but, say you want to list a folder with 1000 images, wouldn't it be extremely slow like that?

ChrisW67
30th September 2010, 00:43
There's no way to do this without at least reading the opening part of each file in the directory and parsing it for the dimension (usually in the file header). Your program would need to know about each file format in order to do this (the IHDR structure for PNG files). Most programs that scan/thumbnail bulk images cache the result because, as you say, this is an expensive operation.

SixDegrees
30th September 2010, 06:53
The only way to find out if it's slow is to try it. It's just a couple lines of code; if you already have a directory that can be used for testing, see what happens when you point at it.

The way every image manipulation program I've seen works is different. They use a preview widget that only gives internal file information when a particular file is clicked on, not for an entire directory at once.

Sadly, Qt did away with their file preview framework for no good reason, so you'll have to roll your own if that's what you want. Most of the signals and slots needed are still in place; there's just no provision for adding a preview widget like there was in the past AND SHOULD BE AGAIN, just in case any Trolls are paying attention.

tbscope
30th September 2010, 07:24
There is at least one way to know the size without opening the file and that is when your system and you yourself keep meta information about every file. Then you only need to read the metadata and not the actual file.