Results 1 to 4 of 4

Thread: how to get dimensions of image file inside a QDir.

  1. #1
    Join Date
    Jun 2010
    Posts
    36
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default how to get dimensions of image file inside a QDir.

    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?
    Last edited by toglia3d; 29th September 2010 at 23:47.

  2. #2
    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: how to get dimensions of image file inside a QDir.

    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.

  3. #3
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: how to get dimensions of image file inside a QDir.

    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.

  4. #4
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: how to get dimensions of image file inside a QDir.

    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.

Similar Threads

  1. Replies: 0
    Last Post: 21st July 2010, 10:32
  2. Highlighted text/image inside delegate
    By hailflex in forum Newbie
    Replies: 0
    Last Post: 11th December 2009, 15:36
  3. [Qt4.1] How to insert an image inside a Form?
    By Gonzalez in forum Qt Tools
    Replies: 5
    Last Post: 23rd September 2008, 11:20
  4. File system utility with more functions than QDir
    By izico in forum Qt Programming
    Replies: 3
    Last Post: 22nd December 2007, 14:44
  5. 3 Dimensions using opengl
    By vermarajeev in forum Qt Programming
    Replies: 30
    Last Post: 23rd April 2007, 11:31

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.