【发布时间】:2015-12-06 17:37:37
【问题描述】:
我想在 swift 中构建一个 iOS 应用来做一些类似绘画应用的事情,但是我在我移动手指的路径上绘制并创建了马赛克。我有两个 imageView photoView 和 tempImageView。 PhotoView 加载照片和 tempImageView 进行绘制。这是一些代码
func drawLineFrom(fromPoint: CGPoint, toPoint: CGPoint) {
UIGraphicsBeginImageContext(photoView.frame.size)
let context = UIGraphicsGetCurrentContext()
tempImageView.image?.drawInRect(CGRect(x: 0, y: 0, width: photoView.frame.size.width, height: photoView.frame.size.height))
CGContextMoveToPoint(context, fromPoint.x, fromPoint.y)
CGContextAddLineToPoint(context, toPoint.x, toPoint.y)
CGContextSetLineCap(context, CGLineCap.Round)
CGContextSetLineWidth(context, brushWidth)
//next line will fill the line with black color but how to fill with mosaic?
CGContextSetRGBStrokeColor(context, 0, 0, 0, 1.0)
CGContextSetBlendMode(context, CGBlendMode.Normal)
CGContextStrokePath(context)
tempImageView.image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
}
我知道下一个代码可以为照片添加过滤器,但是如何将它放在路径或线条上?
var filter = CIFilter(name: "CIPixellate")
let inputImage = CIImage(image: originalImage)
filter.setValue(inputImage, forKey: kCIInputImageKey)
【问题讨论】:
-
是的,但不止于此。
标签: ios swift core-graphics core-image