Gerard Cerchio
Gerard Cerchio

Reputation:

Detecting bad jpeg images

The question on validating jpegs on network transfer is very helpful.

Could we take this question one step further? What if the image data is incomplete or corrupt from the server? The complete transport works, the MIME type is image/jpeg, the UIImage is constructed and non-nil but the renderer discovers inconsistencies in the data and the log shows "Bad Huffman code" or "premature end of data segment"

How would I capture this error before tossing the UIImage into the view context and thereby getting a not-pretty image on the screen? Could I render it to a non-screen context and capture the error?

Upvotes: 1

Views: 312

Answers (1)

xpmatteo
xpmatteo

Reputation: 11408

It seems that the last two bytes in a JPEG image should be FF D9. (see http://www.obrador.com/essentialjpeg/headerinfo.htm)

Upvotes: 2

Related Questions