Quote:
Originally Posted by justin-UK
I am using the Apple GLImageProcessing sample code to change the Hue of an image. This one...
https://developer.apple.com/library/...ion/Intro.html
The image in question is a png with transparency. I must confess I don't fully understand what the OpenGL processing is doing but it seems to be redrawing the image after applying the image processing to it. The result is a loss of the transparency. What was transparent is now white.
Can anyone suggest a way to retain the transparency, or is there a way to mask the redrawn view so that views beneath it can be seen? I have tried applying a mask, and one method is using the graphics 'context' but there is incompatibility and it didn't work.
Thanks for any help. I know I'm out of my depth! but if I could just solve this one thing I can get back in my comfort zone!
|
It sounds to me like the sample app is not using an alpha channel at all. It would probably need to be adjusted to set up the image as RGBA rather than RGB.
Rather than using that very old sample app, I would suggest looking at Apple's new Core Image Filters. They are quite easy to use (although they do require iOS 5. I did some testing with them a while back, and the images I used were partly transparent, so I know for a fact Core Image (CI) filters preserve transparency.
There's a filter, CIHueAdjust, that should let you adjust the hue of an image.
It looks like there is a sample app, "PocketCoreImage" in the Xcode docs that is a working example of using CI filters.
CI is blazingly fast since it uses the GPU. Make sure your image size is 4096 in both dimensions, however. If it is bigger than that CI will have to switch to software rendering, which will be dramatically slower.
It's also very easy to set up. You create a CI filter by name, set a few parameters, and hand it a CIImage. You get back a CIImage, which you then have to convert back to a UIImage. That part is a little tricky however.
UIImage has a method imageWithCIImage that's supposed to let you convert a CIImage to a UIImage, but it's broken in the current version of iOS 5.
Instead, you have to use code like this, courtesy of Erica Sadun, from her excellent new book "The iOS 5 Developer's Cookbook":
Code:
CGImageRef adjustedCGImage = [[CIContext contextWithOptions:nil]
createCGImage: adjustedCIImage
fromRect:inputCIImage.extent];
adjustedUIImage = [UIImage imageWithCGImage: adjustedCGImage];
CFRelease(adjustedCGImage);