2013-09-03 4 views
0

Я хочу обнаружить прозрачную часть изображения uiimageview. Я использую этот код для рисования на uiimageview. Но я хочу обнаружить трансверентную часть в uiimage и предотвратить заполнение цвета этими частями.Обнаружение transperent pixel в uiimageview в IOS

- (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(); 
} 

Заранее спасибо

ответ

1

Там в режиме смеси, которая может помочь вам: kCGBlendModeDestinationOver. Он опирается только на непрозрачные части контекста.

Если вам нужно использовать другие режимы наложения, вы можете преобразовать изображение в маску и закрепить контекст.

Смежные вопросы