tex1001
tex1001

Reputation: 3

UIImage display differently when saving and loading from file

I'm download jpeg picture from web server and load it to UIImage.

If I display the UIImage in UIImageView directly, I see the picture correctly.

But if i cache the image to file with : [UIImageJPEGRepresentation(image,1.0f) writeToFile:sFilePath atoimcally:YES] and load it with :

image=[UIImage imageWithContentsOFile:sFilePath]

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

again, Exactly the same UIImageView object with the same properties settings in it.

Why is that?

Upvotes: 0

Views: 110

Answers (1)

Mundi
Mundi

Reputation: 80265

You can simply write to a file the NSData you have loaded from the web, without going through the UIImageJPEGRepresentation routine.

[dataObject writeToURL:fileURL atomically:YES];

and to retrieve

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

That works really well in my app.

Upvotes: 2

Related Questions