27

I found that in IOS UIImage can change to CIImage.and there is a property CIImage in UIImage. and when i use the UIImage,UIImage object is not null but UIImage.ciimage is null ,why?

forgive my stupid question if someone can help me ,thank you very much.


ADD

for example, the code like below return null:

UIImage *image = [UIImage imageNamed:@"test.jpg"];
CIImage *ciImage = image.CIImage

but if in this way CIImage is not null:

UIImage *image = [UIImage imageNamed:@"test.jpg"];
CIImage *myImage = [[CIImage alloc] initWithCGImage:image.CGImage options:nil];
Xoangle
  • 405
  • 6
  • 11

1 Answers1

44

It is because this UIImage is not in fact a CIImage. In other words, UIImage's CIImage is not nil only if the UIImage is backed by a CIImage already (e.g. because it was generated by imageWithCIImage:). You can't use this to magically turn the UIImage into a CIImage, as you seem to be hoping to do.

The documentation is actually pretty clear on this. Always worth a read.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • 1
    @matt How can you convert from UIImage to CIImage then? – brimstone Mar 23 '16 at 18:04
  • 6
    @brimstone With CIImage's `initWithImage:` initializer. – matt Mar 23 '16 at 18:10
  • 2
    I have found that sometimes going straight from CIImage to UIImage doesn't always work. I convert CIImage to CGIImage and then to UIImage and it works just fine. – Munib Dec 30 '16 at 02:45