Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I've been wrestling with a similar local image corruption problem for a few months in my production app (using <code>UIImageJPEGRepresentation()</code> in my case), and in my case it had nothing to do with downloading the image - but the local storage and rendering.</p> <p>In my case, the actual user effect of the error was that the image would only partially render; the remainder of the image simply appear gray and corrupt. I am storing and reading from the disk using Core Data (but Core Data was shockingly not my problem).</p> <p><strong>MY FIX:</strong></p> <p>I was formerly using this convenience method:</p> <pre><code>UIImage *image = [UIImage imageWithContentsOfFile:imagePath]; </code></pre> <p>..but on the advice of <a href="https://stackoverflow.com/questions/5081297/ios-uiimagejpegrepresentation-error-not-a-jpeg-file-starts-with-0xff-0xd9">some other related posts here</a>, I switched to this combination of methods instead:</p> <pre><code>NSData *resultData = [NSData dataWithContentsOfFile:imagePath]; UIImage *image = [UIImage imageWithData:resultData]; </code></pre> <p>..and it SEEMS to have solved my problem!</p> <p><strong>MY THEORY</strong></p> <p>I'm guessing that <code>imageWithContentsOfFile:</code> is, for some reason, worse at handling some non-atomical edge case conditions vs. the pure base <code>NSData</code> calls, and it is for some reason allowing a 'read' to begin before the previous 'write' has completed.</p> <p>Hope this helps! Good luck.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload