rptwsthi
rptwsthi

Reputation: 10172

can I check if downloaded image is corrupt or not before saving?

can I check if downloaded image is corrupt or not before saving it into my document directory? if yes then please tell me how? thank you

Upvotes: 3

Views: 1331

Answers (2)

rckoenes
rckoenes

Reputation: 69489

You could try to load the NSData object in a UIIImage with the initData. Then check if the return UIImage object is nil. This is not full proof methods, but should work.

Upvotes: 0

Stefan Ticu
Stefan Ticu

Reputation: 2103

UIImage *im = [[UIImage alloc] initWithData:YourNSData];
UIImageView *imview;

// test to see if the image was successfully created
if (im){
   imview = [[UIImageView alloc] initWithImage:im];
}

Hope this helps

Upvotes: 1

Related Questions