Iphone UIImage在保存和从文件加载时显示不同
我正在从web服务器下载jpeg图片并将其加载到UIImage 如果我直接在UIImageView中显示UIImage,则可以正确地看到图片 但如果我将图像缓存到文件中: [UIImageJPEG表示(图像,1.0f)写入文件:sFilePath原子:是] 并加载以下内容:Iphone UIImage在保存和从文件加载时显示不同,iphone,objective-c,ios,Iphone,Objective C,Ios,我正在从web服务器下载jpeg图片并将其加载到UIImage 如果我直接在UIImageView中显示UIImage,则可以正确地看到图片 但如果我将图像缓存到文件中: [UIImageJPEG表示(图像,1.0f)写入文件:sFilePath原子:是] 并加载以下内容: image=[UIImage imageWithContentsOFile:sFilePath] and display this in the same UIImageView, I can see white stri
image=[UIImage imageWithContentsOFile:sFilePath]
and display this in the same UIImageView, I can see white stripes in the sides of the picture.
同样,完全相同的UIImageView对象具有相同的属性设置
这是为什么?您只需将从web加载的
NSData
写入文件,而无需执行uiimagejpegresentation
例程
[dataObject writeToURL:fileURL atomically:YES];
和取回
UIImage *image = [[UIImage alloc] initWithContentsOfFile:[fileURL path]];
这在我的应用程序中非常有效。在缓存到文件后,您应该尝试使用图像编辑器加载图像文件,以查看条纹是在写入步骤中引入的,还是在重新读取时引入的。