So I am making a call to pull an image from a photo server using Nimbus' NINetworkImageView object. I need to check if the object returned is valid. If it is not valid, the method
- (void) networkImageView:(NINetworkImageView *) imageView didLoadImage:(UIImage *) image {
returns a transparent UIImage object. I think the method is returning me a jpg image with clear pixels which is causing me the issue. I have tried the following checks to see if the image is transparent with no luck (All of the attempts below happen in the scope of the method above):
Failed Attempt 1:
UIImageView *tempView = [[UIImageView alloc] initWithImage:image];
if(tempView.alpha != 0.0f)
{
//the image is a valid (nonclear) image
}
else
{
//the image is invalid (clear)
}
Failed Attempt 2:
CGImageRef cgref = [[UIImage alloc] CGImage];
CIImage *cim = [[UIImage alloc] CIImage];
if(!([image CIImage] == cim && [image CGImage] == cgref))
{
//the image is a valid (nonclear) image
}
else
{
//the image is invalid (clear)
}
Failed Attempt 3:
if(image)
{
//the image is a valid (nonclear) image
}
else
{
//the image is invalid (clear)
}
Failed Attempt 4:
CGImageRef cgref = [image CGImage];
CIImage *cim = [image CIImage];
if(cim == nil && cgref == NULL)
{
//the image is invalid (clear)
}
else
{
//the image is a valid (nonclear) image
}
Edit
I was able to pull the "Invalid image" from the simulator. The networkimageview method is returning a jpg image that is completely white. However, in the simulator it shows up as a clear picture, thoughts?
I can advice to save this image to disk and see it's alpha value in Photoshop/another graphic tool.
Now you can find this image in Photos app.
The following function saves UIImage with name
image.png
file in the user Document folder: