How to quickly determine whether a file is an image file using iPhone/iPad SDK

Posted by Josh Bleecher Snyder on Stack Overflow See other posts from Stack Overflow or by Josh Bleecher Snyder
Published on 2010-04-14T16:19:20Z Indexed on 2010/04/14 16:23 UTC
Read the original article Hit count: 618

Filed under:
|
|
|

If I have a (potentially largish) file on disk, and I want to determine quickly whether UIImage will be able to load it.

I don't necessarily trust the file extension to be reliable; I need to look at the actual data.

I can (of course) load it into a UIImage, but that's relatively slow and rather memory intensive. I'd rather just peek at the first chunk of the file and make a decision.

What's the fastest, most efficient way to go about this that is still fairly reliable? (Ideally, it'd be an Apple-provided API, but I didn't turn one up in my searches.) A 99.9% solution is good enough; I'm willing to have false positives in rare cases, such as when an image file has been truncated.

© Stack Overflow or respective owner

Related posts about iphone-sdk

Related posts about ipad-sdk