捕获错误:损坏的 JPEG 数据:数据段过早结束
当使用损坏/不完整的 JPEG 数据创建 UIImage 时,控制台将打印出
将显示不完整的图像,并用灰色填充不完整的图像部分。我不希望这种情况发生。
我拼命尝试使用 try-catch 块,但它没有捕获错误。有什么办法可以捕获错误吗?
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 not catch the error. Is there any way to catch the error?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
针对上面Slee的问题,这是我使用的方法:
In response to Slee's question above, this is the method I use:
取决于您如何获取数据等。也许这就是您正在寻找的: iphone-corrupt-jpeg-data-for-image-received-over-http
检查 JPEG 数据是否完整的简单方法是检查 FF 的前两个字节和最后两个字节分别为 D8 和 FF D9。这两个字节分别标识 JPEG 文件的开始和结束。
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.