I want to take an objective-c UIImage and make it all black, but still have the same alpha values so that it becomes a silhouette of its former image. I was wondering is there any more convenient way to do this than just taking the CGImage data and changing the values for each pixel?
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- back button text does not change
- SwiftUI: UIImage (QRCode) does not load after call
- iOS (objective-c) compression_decode_buffer() retu
相关文章
- 现在使用swift开发ios应用好还是swift?
- TCC __TCCAccessRequest_block_invoke
- xcode 4 garbage collection removed?
- Xcode: Is there a way to change line spacing (UI L
- Unable to process app at this time due to a genera
- How can I add media attachments to my push notific
- didBeginContact:(SKPhysicsContact *)contact not in
- Custom Marker performance iOS, crash with result “
Here is a function I have used to make a colorized version of an image:
It utilizes the NSCompositeDestinationIn operation to fill in opaque areas of the image with the desired color.
You can extract the alpha info by creating a CGBitmapContext with kCGImageAlphaOnly, and 1 component and draw into that. Then you'd have an image with alpha only.
Then you could composite that onto an entirely black image with kCGBlendModeDestinationIn. That should leave you with an image that's all black with the original alpha values.