I'm trying to create a UIImage
from the ALAssetsGroup#posterImage
method. In Objective-C, I could simply call [UIImage imageWithCGImage:group.posterImage]
but in Swift, UIImage(CGImage: group.posterImage)
gives me a compiler error:
Could not find an overload for 'init' that accepts the supplied arguments
What am I doing wrong?
This is most compatibile way of doing it: UIImage* u =[UIImage imageNamed:@"image. png"]; CIImage* ciimage = [[CIImage alloc] initWithCGImage:u. CGImage];
An object that manages image data in your app.
A bitmap image or image mask.
If you look at the docs in Xcode6 you will see that posterImage()
returns a Unmanaged<CGImage>!
(in Swift, in ObjC it returns a CGImageRef
). After some investigation from the docs I found this:
When you receive an unmanaged object from an unannotated API, you should immediately convert it to a memory managed object before you work with it.
So your solution would be:
UIImage(CGImage: group.posterImage().takeUnretainedValue())
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With