我正在将一个 .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提供给了单元格中的图像视图。我设置了图像视图属性,以便所有单元格中的图像排成一行并且大小相同,但我认为这与将UIImage转换为NSData无关。
myImage
的? - Dylan Copeland