捕获错误:损坏的JPEG数据:数据段的过早结束 [英] Catching error: Corrupt JPEG data: premature end of data segment
问题描述
创建包含损坏/不完整JPEG数据的UIImage时,控制台将打印出来
When creating an UIImage with corrupt/incomplete JPEG data, the console will print out
<错误>:损坏的JPEG数据:过早数据段结束
将显示未完整的图像,灰色填满不完整的部分。我不希望这种情况发生。
The incomplete image will be shown, with grey filling up the incomplete part. I do not want this to happen.
我拼命尝试使用try-catch块,但它没有发现错误。有没有办法来捕捉错误?
I desperately tried with a try-catch block but it does not catch the error. Is there any way to catch the error?
推荐答案
取决于你如何获取数据等。也许这就是你的意思寻找: iphone-corrupt-jpeg-data-for-image -ceceived-over-http
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
检查JPEG数据是否完整的一种简单方法是检查FF D8的前两个字节和FF D9分别。这两个字节分别标识JPEG文件的开头和结尾。
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.
这篇关于捕获错误:损坏的JPEG数据:数据段的过早结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!