PDA

View Full Version : QImage, get file format



greenvirag
27th December 2008, 21:51
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

jpn
27th December 2008, 23:02
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.

aamer4yu
29th December 2008, 08:35
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 :)

greenvirag
29th December 2008, 14:06
Ok, then I ask my question a little other way. :)

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

jpn
29th December 2008, 14:12
See QFileInfo.

caduel
29th December 2008, 14:13
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

aamer4yu
29th December 2008, 14:13
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