[Qt-interest] Find Picture file

Oliver.Knoll at comit.ch Oliver.Knoll at comit.ch
Mon Dec 1 12:59:58 CET 2008


Daniel Hartwig wrote on Monday, December 01, 2008 12:21 PM:
> ..
> now my Problem is, that i didn't know how to find the picture,
> because it can be have gif/jpeg /jpg/png/... Picturetype. But in my
> function i get the name.

That's the canonical "Guess what file type this is!"-problem. There are several approaches: Windows entirely relies on the file name extension, so you would filter for *.jpg, *.bmp, *.gif etc. (I assume that with "but in my function I get the name" you mean "the file name, including extension").

A good start would be to stick to the image formats your application actually can read: http://doc.trolltech.com/4.4/qimagereader.html#supportedImageFormats

A bit more reliable would be to "parse" the first few bytes of the unknown file and look for a "magic number". That's how Linux/Unix does it (in certain cases, for example "Konqueror" (KDE file manager) AFAIK):

  http://en.wikipedia.org/wiki/Magic_number_(programming)

There might be 3rd party libraries which do this for you.

Cheers, Oliver




More information about the Qt-interest-old mailing list