Próbując uzyskać CIImage od UIImage w celu wykorzystania go do CIFilter, ale otrzymuję następujący wyjątek w ostatnim wierszu:Pierwsze CIImage z UIImage (Swift)
Execution was interrupted, reason: EXC_BREAKPOINT (code=EXC_I386_BPT, subcode=0x0)
Co robię źle?
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: zgodnie z zaleceniami nie instancję CIImage jako zmienna I przerobione mój kod początkowy fragment do pracy na placu zabaw:
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)
To zawiedzie na placu zabaw, ale działa dla mnie skompilowanym kodem - musi być dziwactwem środowiska zabaw. –
Tak, działa również po skompilowaniu dla mnie. –