8
試圖從UIImage的,以將其用於CIFilter獲得CIImage,但收到以下異常在最後一行:獲取CIImage從UIImage的(SWIFT)
Execution was interrupted, reason: EXC_BREAKPOINT (code=EXC_I386_BPT, subcode=0x0)
我在做什麼錯?
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作爲可變我返工我最初的代碼片段在操場的工作:
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)
這失敗了在操場上,但在編譯代碼爲我工作 - 必須是一個怪癖操場環境。 – 2014-11-23 04:08:21
是的,我也爲我編譯。 – 2014-11-23 04:33:43