views:

66

answers:

1

When creating an UIImage with corrupt/incomplete JPEG data, the console will print out

<Error>: Corrupt JPEG data: premature end of data segment

The incomplete image will be shown, with grey filling up the incomplete part. I do not want this to happen.

I desperately tried with a try-catch block but it does catch the error. Is there any way to catch the error?

+1  A: 

Depends on how you are getting the data etc. Maybe this is what you are looking for: iphone-corrupt-jpeg-data-for-image-received-over-http

A simple way to check if the JPEG data is complete or not is to check the first and last two bytes for FF D8 and FF D9 respectively. Those two bytes identify the start and end of a JPEG file respectively.

Vaayu
This would work as a solution for my purpose. But I am still curious how the error can be catch.
samwize
The first 2 bytes should be FF D8
samwize