从文件保存和加载时,UIImage的显示方式不同

时间:2011-08-14 18:20:19

标签: iphone objective-c ios

我从网络服务器下载jpeg图片并将其加载到UIImage。

如果我直接在UIImageView中显示UIImage,我会正确看到图片。

但是,如果我将图像缓存到文件:      [UIImageJPEGRepresentation(image,1.0f)writeToFile:sFilePath atoimcally:YES]     并加载:

image=[UIImage imageWithContentsOFile:sFilePath]

and display this in the same UIImageView, I can see white stripes in the sides of the picture.

再次,完全相同的UIImageView对象,其中包含相同的属性设置。

为什么?

1 个答案:

答案 0 :(得分:2)

您只需将从网络加载的NSData写入文件,而无需通过UIImageJPEGRepresentation例程。

[dataObject writeToURL:fileURL atomically:YES];

并检索

UIImage *image = [[UIImage alloc] initWithContentsOfFile:[fileURL path]];

在我的应用中效果非常好。