gpt4 book ai didi

iphone - iOS UIImageJPEGRepresentation错误: Not a JPEG file: starts with 0xff 0xd9

转载 作者:行者123 更新时间:2023-12-03 18:28:22 28 4
gpt4 key购买 nike

我正在将 .jpg 文件写入我的应用程序的文档目录,如下所示:

NSData *img = UIImageJPEGRepresentation(myUIImage, 1.0);
BOOL retValue = [img writeToFile:myFilePath atomically:YES];

稍后,我使用以下方法将该图像加载回 UIImage:

UIImage *myImage = [UIImage imageWithContentsOfFile:path];

我知道它有效,因为我可以在表格单元格中绘制图像,而且效果很好。现在,如果我尝试使用 UIImageJPEGRepresentation(myImage, 1.0),调试器会打印出这些行:

<Error>: Not a JPEG file: starts with 0xff 0xd9
<Error>: Application transferred too few scanlines

该函数返回 nil。有人知道为什么会发生这种情况吗?加载 UIImage 数据后,我没有做任何操作。我刚刚将 UIImage 提供给单元格中的 ImageView 。我设置了 ImageView 属性,使单元格中的所有图像对齐且大小相同,但我认为这与能够将 UIImage 转换为 NSData 没有任何关系。

最佳答案

图像没有损坏,我能够正确显示它们。该问题可能是 UIImage 中的错误,或者文档可能应该更清楚地了解如何使用 imageWithContentsOfFile:。

我能够通过更改来消除错误消息

UIImage *myImage = [UIImage imageWithContentsOfFile:path];

NSData *img = [NSData dataWithContentsOfFile:path];
UIImage *photo = [UIImage imageWithData:img];

关于iphone - iOS UIImageJPEGRepresentation错误: Not a JPEG file: starts with 0xff 0xd9,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5081297/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com