首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从CIImage获得UIImage (Swift)

从CIImage获得UIImage (Swift)
EN

Stack Overflow用户
提问于 2014-11-23 03:17:28
回答 2查看 7.6K关注 0票数 11

尝试从CIImage中获取UIImage,以便将其用于CIFilter,但在最后一行获得以下异常:

代码语言:javascript
复制
Execution was interrupted, reason: EXC_BREAKPOINT (code=EXC_I386_BPT, subcode=0x0)

我做错了什么?

代码语言:javascript
复制
import UIKit

UIGraphicsBeginImageContextWithOptions(CGSizeMake(100,100), false, 0)
let con:CGContextRef = UIGraphicsGetCurrentContext()
CGContextAddEllipseInRect(con, CGRectMake(0,0,100,100))
CGContextSetFillColorWithColor(con, UIColor.blueColor().CGColor)
CGContextFillPath(con)
let im:UIImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()

let ciimage = CIImage(image: im) // <- Exception here

UPDATE:遵循不将CIImage实例化为变量的建议,重新编写了初始代码片段,以便在操场上工作:

代码语言:javascript
复制
UIGraphicsBeginImageContextWithOptions(CGSizeMake(100,100), false, 0)
let con:CGContextRef = UIGraphicsGetCurrentContext()
CGContextAddEllipseInRect(con, CGRectMake(0,0,100,100))
CGContextSetFillColorWithColor(con, UIColor.blueColor().CGColor)
CGContextFillPath(con)
let im:UIImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()

//let ciimage = CIImage(image: im) // <- this was causing an exception

let filter = CIFilter(name: "CIGaussianBlur", withInputParameters: [kCIInputRadiusKey: 10, kCIInputImageKey: CIImage(image: im)]) // <- this does not cause an exception
let calayer = CALayer()
calayer.contents = CIContext(options:nil).createCGImage(filter.outputImage, fromRect: filter.outputImage.extent())
calayer.frame = CGRect(x: 0, y: 0, width: 270, height: 270)
var view = UIView()
view.frame = calayer.frame
view.layer.addSublayer(calayer)
XCPShowView("view", view)
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-12-24 15:27:02

如果您正在尝试使用过滤器,那么我解决了这个操场错误:

代码语言:javascript
复制
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())
票数 10
EN

Stack Overflow用户

发布于 2021-06-11 02:50:02

有可能在一条线上。

UIImage > CIImage

代码语言:javascript
复制
let ciimage = CIImage(image: image)

CIImage > UIImage

代码语言:javascript
复制
let image = UIImage(ciImage: ciimage)
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27085225

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档