I am trying to make a drawing app that has a control on the opacity of the brush but when I tried to lower the opacity the result is like this - Picture. I used core graphics. How to fix this problem?
Some my code:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
mouseSwiped = NO;
UITouch *touch = [touches anyObject];
lastPoint = [touch locationInView:self.imageViewProperty];}
- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
mouseSwiped = YES;
UITouch *touch = [touches anyObject];
CGPoint currentPoint = [touch locationInView:self.imageViewProperty];
UIGraphicsBeginImageContext(self.imageViewProperty.frame.size);
[self.imageViewProperty.image drawInRect:CGRectMake(0, 0, self.imageViewProperty.frame.size.width, self.imageViewProperty.frame.size.height)];
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x, currentPoint.y);
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 10);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), redColorValue, greenColorValue, blueColorValue, alphaValue);
CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeNormal);
CGContextStrokePath(UIGraphicsGetCurrentContext());
self.imageViewProperty.image = UIGraphicsGetImageFromCurrentImageContext();
[self.imageViewProperty setAlpha:1.0f];
UIGraphicsEndImageContext();
lastPoint = currentPoint;}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
if(!mouseSwiped) {
UIGraphicsBeginImageContext(self.view.frame.size);
[self.imageViewProperty.image drawInRect:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(), 10);
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), redColorValue, greenColorValue, blueColorValue, alphaValue);
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), lastPoint.x, lastPoint.y);
CGContextStrokePath(UIGraphicsGetCurrentContext());
CGContextFlush(UIGraphicsGetCurrentContext());
self.imageViewProperty.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
UIGraphicsBeginImageContext(self.mainImageProperty.frame.size);
[self.mainImageProperty.image drawInRect:CGRectMake(0, 0, self.mainImageProperty.frame.size.width, self.mainImageProperty.frame.size.height)
blendMode:kCGBlendModeNormal
alpha:1.0];
self.mainImageProperty.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();}