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

前端 未结 2 1046
孤街浪徒
孤街浪徒 2021-01-14 03:37

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

相关标签:
2条回答
  • 2021-01-14 04:29
    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

    0 讨论(0)
  • 2021-01-14 04:32

    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.

    0 讨论(0)
提交回复
热议问题