У меня есть одно изображение, где пользователи могут закрашивать его. Для рисования я использую что-то вроде:
override func touchesEnded(touches: Set<NSObject>, withEvent event: UIEvent) {
if (touches.count == 1) {
let touch = touches.first as! UITouch
if (touch.tapCount == 1) {
let touch = touches.first as! UITouch
let currentPoint = touch.locationInView(self)
UIGraphicsBeginImageContextWithOptions(self.frame.size, false, self.scale)
self.image?.drawInRect(CGRectMake(0, 0, self.frame.size.width, self.frame.size.height))
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound)
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), self.width);
CGContextSetStrokeColorWithColor(UIGraphicsGetCurrentContext(), UIColor.whiteColor().colorWithAlphaComponent(1.0).CGColor);
CGContextBeginPath(UIGraphicsGetCurrentContext());
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), startPoint.x, startPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y)
CGContextStrokePath(UIGraphicsGetCurrentContext());
self.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
}
}
В результате получается белая линия над исходным изображением.
Затем на следующем экране я хочу показать только нарисованную линию, но в прозрачном цвете, чтобы можно было показать исходное изображение. Я пытаюсь применить маски, но белая линия не совсем прозрачна.
func mergeImages(image: UIImage) {
let maskImage = UIImage(named: "03-tobacco.png")
let maskRef = maskImage?.CGImage;
let mask = CGImageMaskCreate(
CGImageGetWidth(maskRef),
CGImageGetHeight(maskRef),
CGImageGetBitsPerComponent(maskRef),
CGImageGetBitsPerPixel(maskRef),
CGImageGetBytesPerRow(maskRef),
CGImageGetDataProvider(maskRef),
nil,
false)
let masked = CGImageCreateWithMask(image.CGImage, mask)
let maskedImage = UIImage(CGImage: masked)!
self.signatureImage.image = maskedImage
}
Как я могу этого добиться?