Unable to convert CIImage to UIImage in Swift 3.0
func convert(cmage:CIImage) -> UIImage
{
let context:CIContext = CIContext.init(options: nil)
let cgImage:CGImage = context.createCGImage(cmage, from: cmage.extent)!
let image:UIImage = UIImage.init(cgImage: cgImage)
return image
}
Use this function to convert CIImage to UIImage . It works .
CIImage Convert to UIImage
you will call init for resolve this issue
imgurl.image = UIImage.init(ciImage: transformedImage)
Create UIImage from CIImage on iOS 10
You can use following :
Objective C:
CIImage *ciImage = [blob image];
UIImage *uiImage = [[UIImage alloc] initWithCIImage:ciImage];
Swift 4.0:
let ciImage: CIImage? = blob.image()
let uiImage = UIImage(ciImage: ciImage!)
CIImage to UIImage Distorts Color SWIFT
So my convert function was not correctly initializing the CIContext. Here's the corrected method:
func convert(ciImage:CIImage) -> UIImage?
{
let context = CIContext(options: [CIContextOption.workingColorSpace: kCFNull!])
if let cgImage:CGImage = context.createCGImage(ciImage, from: ciImage.extent, format: .RGBA8, colorSpace: CGColorSpace.init(name: CGColorSpace.sRGB)!) {
let image:UIImage = UIImage.init(cgImage: cgImage)
return image
}
return nil
}
Unable to convert CIImage to UIImage in Swift 3.0
func convert(cmage:CIImage) -> UIImage
{
let context:CIContext = CIContext.init(options: nil)
let cgImage:CGImage = context.createCGImage(cmage, from: cmage.extent)!
let image:UIImage = UIImage.init(cgImage: cgImage)
return image
}
Use this function to convert CIImage to UIImage . It works .
How to Convert UIImage to CIImage and vice versa
CIImage *ciImage = [UIImage imageNamed:@"test.png"].CIImage;
UIImage *uiImage = [[UIImage alloc] initWithCIImage:ciImage];
To fix the case where myUIImage.CIImage
returns nil
like [UIImageView image]
, you can instead do [CIImage imageWithCGImage:myUIImage.CGImage]
– Dylan Hand
Swift version:
let ciImage = UIImage(named: "test.png")!.ciImage
let uiImage = UIImage(ciImage: ciImage)
To fix the case where myUIImage.ciImage
returns nil
like you can instead do CIImage(cgImage: myUIImage!.cgImage!)
.
Getting CIImage from UIImage (Swift)
If you are trying to work with filters, I worked around this playground bug:
let pic = UIImage(named: "crumpled.jpg")
let filter = CIFilter(name: "CISepiaTone")
filter.setValue(CIImage(image: pic), forKey: kCIInputImageKey)
filter.setValue(0.8, forKey: kCIInputIntensityKey)
let ctx = CIContext(options:nil)
let cgImage = ctx.createCGImage(filter.outputImage, fromRect:filter.outputImage.extent())
Related Topics
Makekeywindow VS Makekeyandvisible
Xcode 7 Beta 6, Dyld _Nsarray0_ Crash
Hide a Phone Call Completely in iOS (Jailbreak Device)
How We Can Set the Light Content Style of Status Bar in iOS 9 for Whole Application
Autolayout: Uiview Within Uiview Has Incorrect Frame
iOS Library to Convert Powerpoint Presentations into Images
How to Add External Webvtt Subtitles into Http Live Stream on iOS Client
Memory Leak with "Libbacktracerecording.Dylib" in React Native iOS Application
Uiwebview Not Go to Didfailloadwitherror When Weblink Not Found
Cashapelayer Animating Path Glitches/Flickers (From Ellipse to Rect and Back)
How to Sort 1 Array in Swift/Xcode and Reorder Multiple Other Arrays by the Same Keys Changes
Undefined Symbols for Architecture Arm64 "_Objc_Class_$_Sfsafariviewcontroller"
Uiwebview Stringbyevaluatingjavascriptfromstring Hangs on iOS5.0/5.1 When Called Using Gcd
Uiapplicationlaunchoptionsremotenotificationkey Not Getting Userinfo
How to Add Navigation Interface After Create a Tab Bar Controller Programmatically (Swift)