Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIImage, check if contain image

Tags:

ios

uiimage

If I instantiate a UIImage like this :

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

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

How I can check if my object contains an image or not?

like image 866
Jonathan Avatar asked Nov 18 '11 09:11

Jonathan


1 Answers

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") } 
like image 113
Kreiri Avatar answered Sep 19 '22 02:09

Kreiri