views:

46

answers:

2

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.

A: 

Are you worried about image corruption? Why not read the signature from the file and determine if its in a list of supported image formats?

CDSO1
Worried about (a) not knowing which of the various image formats UIImage supports -- it appears to vary by platform, (b) having a reliable, exhaustive set of signatures. (By signature I assume you mean the magic bytes at the beginning.) I'm mostly worried about the variety of RAW formats, making sure I have good coverage, etc. That's why I was hoping for something official or some trick/technique using the official API or an open source project/listing that I could use.
Josh Bleecher Snyder
I have not looked into it, but perhaps this will help:http://developer.apple.com/mac/library/samplecode/MassiveImage/Introduction/Intro.html#//apple_ref/doc/uid/DTS10004468It should provide a method to query the image information without loading the file
CDSO1
Looked promising...but that sample code is a way to provide already decoded pixel data to a process that is going to handle it. I need the opposite -- a way to incrementally ask for decoded pixel data from an existing file. It's a good start for future investigation, though -- thanks!
Josh Bleecher Snyder
A: 

There is no Apple API for dealing with corrupt files.

Azeem.Butt