我想检测 uiimageview 的透明部分。我正在使用此代码绘制到 uiimageview。但我想检测 uiimage 中的透明部分并防止将颜色填充到这些部分中。
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
// CGFloat red,green,blue,alpha;
UITouch *touch1 = [touches anyObject];
CGPoint currentPoint = [touch1 locationInView:Image_apple];
UIGraphicsBeginImageContext(Image_apple.frame.size);
[Image_apple.image drawInRect:CGRectMake(0, 0, Image_apple.frame.size.width, Image_apple.frame.size.height)];
CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeNormal);
// CGContextSetBlendMode(UIGraphicsGetCurrentContext(),[self getBlendMode]);
CGContextMoveToPoint(UIGraphicsGetCurrentContext(), lastPoint.x , lastPoint.y );
CGContextAddLineToPoint(UIGraphicsGetCurrentContext(), currentPoint.x , currentPoint.y );
CGContextSetLineCap(UIGraphicsGetCurrentContext(), kCGLineCapRound);
CGContextSetLineWidth(UIGraphicsGetCurrentContext(),8.0 );
// [[self getPaintColor] getRed:&red green:&green blue:&blue alpha:&alpha];
CGContextSetRGBStrokeColor(UIGraphicsGetCurrentContext(), 1, 0.5, 0.2, 1);
CGContextSetBlendMode(UIGraphicsGetCurrentContext(),kCGBlendModeNormal);
CGContextStrokePath(UIGraphicsGetCurrentContext());
Image_apple.image = UIGraphicsGetImageFromCurrentImageContext();
[Image_apple setAlpha:1];
UIGraphicsEndImageContext();
}
提前致谢