Results 1 to 7 of 7

Thread: QImage, get file format

  1. #1
    Join Date
    Sep 2008
    Posts
    17
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QImage, get file format

    Hi!

    I have a problem, maybe with a trivial answer.
    How can I get the file format of an QImage?

    There is a format() function, but it is an enum, like QImage::Format_Invalid, QImage::Format_Mono, QImage::Format_MonoLSB, QImage::Format_Indexed8, QImage::Format_RGB32, QImage::Format_ARGB32, but I need this information in the following form: char* like PNG, JPG, JPEG, etc.

    What is the easiest solution for this problem?

    Thank you,
    greenvirag

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QImage, get file format

    QImage can load and save images in various file formats listed by:
    • QImageReader::supportedImageFormats()
    • QImageWriter::supportedImageFormats()

    but after QImage has the image data loaded to memory, it doesn't really care what was the file format. All it cares about is the image format defining how the image data is stored in memory.
    J-P Nurmi

  3. #3
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QImage, get file format

    There is a format() function, but it is an enum, like QImage::Format_Invalid, QImage::Format_Mono, QImage::Format_MonoLSB, QImage::Format_Indexed8, QImage::Format_RGB32, QImage::Format_ARGB32, but I need this information in the following form: char* like PNG, JPG, JPEG, etc.

    What is the easiest solution for this problem?
    best thing would be store the format urself when u load the image

  4. #4
    Join Date
    Sep 2008
    Posts
    17
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QImage, get file format

    Ok, then I ask my question a little other way.

    If I open a file, how can I get the file type/extension?

  5. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QImage, get file format

    See QFileInfo.
    J-P Nurmi

  6. #6
    Join Date
    Dec 2006
    Posts
    849
    Thanks
    6
    Thanked 163 Times in 151 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QImage, get file format

    Have a look at QFileInfo::completeSuffix().
    (Of course, that function might be cheated if a file is named .png but isn't reallz a png... if you want/need to check that too, you might want to use the "file" utility.)

    HTH

  7. #7
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QImage, get file format

    If you want to go the harder way...
    Files usually have a signature by which they are identified. These signatures are stored as first few bytes of the file.
    You can read these bytes and determine which file they are.
    For eg., jpg files have a signature of "FFD8FFE0"

    Hope this helps

Similar Threads

  1. get QImage object from buffer
    By Sheng in forum Qt Programming
    Replies: 2
    Last Post: 21st September 2012, 02:03
  2. Set up the Qt4.3.2 with Visual Studio 2005
    By lamoda in forum Installation and Deployment
    Replies: 6
    Last Post: 30th January 2008, 06:51
  3. Some very weird compilation warnings
    By MarkoSan in forum Qt Programming
    Replies: 21
    Last Post: 23rd January 2008, 16:48
  4. qt-3.3.8 fail in scratchbox
    By nass in forum Installation and Deployment
    Replies: 0
    Last Post: 25th May 2007, 15:21
  5. Replies: 13
    Last Post: 1st June 2006, 14:01

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.