Convert CIImage to CGImageRef, which can be used to create a GLK texture

I have a CIImage that is a sample of the CIFilter result / output. Now I want to create a texture for this image using GLKTextureLoader. I am using the following function, which requires a CGImageRef.

[GLKTextureLoader textureWithCGImage: options: error:]; 

So the question is, what is the best way to convert CIImage to CGImageRef that GLKTextureLoader can use?

I tried the following method, but this failed:

 CIContext *context = [CIContext contextWithOptions:nil]; CGImageRef ref = [context createCGImage:fullScreenCI fromRect:fullScreenCI.extent]; self.info = [GLKTextureLoader textureWithCGImage:ref options:nil error:&error]; 

fullscreenCI is the outputImage CIFilter.

The above method gives the following error:

error creating GLK texture: Domain error = GLKTextureLoaderErrorDomain Code = 12 "Operation could not be performed. (GLKTextureLoaderErrorDomain error 12.)" UserInfo = 0x1438a880 {GLKTextureLoaderErrorKey = image decoding failed}

I realized that this could be due to a problem with the flower space and tried the following method:

 CIContext *context = [CIContext contextWithOptions:nil]; CGImageRef ref = [context createCGImage:fullScreenCI fromRect:fullScreenCI.extent]; fullscreen = [UIImage imageWithData:UIImagePNGRepresentation([UIImage imageWithCGImage:ref])]; self.info = [GLKTextureLoader textureWithCGImage:fullscreen.CGImage options:nil error:&error]; 

Now this method works fine! But I want to know if there is a better way to convert CIImage to CGImageRef without having to use the UIImagePNGR view.

+4
source share

Source: https://habr.com/ru/post/1493583/


All Articles