I have drawn into a CGContext of a UIView.
- (void)drawRect:(CGRect)rect {
[self drawInContext:UIGraphicsGetCurrentContext()]
}
I wo
let imageWidth = inputCGImage.width
let imageHeight = inputCGImage.height
let imageRect = NSRect(
origin: .zero,
size: CGSize(width: imageWidth, height: imageHeight)
)
context.draw(inputCGImage, in: imageRect)
let outputImageRef = context.makeImage()!
let paths = NSSearchPathForDirectoriesInDomains(.desktopDirectory, .userDomainMask, true) as [String]
let destinationURL = NSURL(fileURLWithPath: paths.first!).appendingPathComponent("output.png")!
guard let destination = CGImageDestinationCreateWithURL(destinationURL as CFURL, kUTTypePNG, 1, nil) else {
throw HoleFillingError.CoreGraphicsError
}
CGImageDestinationAddImage(destination, outputImageRef, nil)
CGImageDestinationFinalize(destination)