UIImage, check if contain image

后端 未结 4 922
别那么骄傲
别那么骄傲 2020-12-24 01:51

If I instantiate a UIImage like this :

UIImage *image = [[UIImage alloc] init];

The object is created but it doesn\'t contain any image.

4条回答
  •  佛祖请我去吃肉
    2020-12-24 02:45

    You can check if it has any image data.

    UIImage* image = [[UIImage alloc] init];
    
    CGImageRef cgref = [image CGImage];
    CIImage *cim = [image CIImage];
    
    if (cim == nil && cgref == NULL)
    {
        NSLog(@"no underlying data");
    }
    [image release];
    

    Swift Version

    let image = UIImage()
    
    let cgref = image.cgImage
    let cim = image.ciImage
    
    if cim == nil && cgref == nil {
        print("no underlying data")
    }
    

提交回复
热议问题