2016-04-25 58 views
0

我有UIImage與一些圖像。如何添加路徑到UIImage,它將刪除像素?

而我有UIBezierPath(用戶簽名)。

如何在UIImage中爲alpha刪除像素。

就像劃傷一些uiimage?

我嘗試

UIGraphicsBeginImageContextWithOptions(self.bounds.size, YES, 0.0); 
    [[UIColor clearColor] setStroke]; 

    [self.blurImageView.image drawAtPoint:CGPointZero]; 
    CGContextSetBlendMode(UIGraphicsGetCurrentContext(), kCGBlendModeClear); 
    [self.path stroke]; 
    UIImage *img = UIGraphicsGetImageFromCurrentImageContext(); 
    UIGraphicsEndImageContext(); 

    self.blurImageView.image = img; 

,但它只是畫黑線。

回答

3

您正在將YES傳遞給參數UIGraphicsBeginImageContextWithOptionsopaque。因此,而不是創建透明度,kCGBlendModeClear將填充黑色(因爲沒有alpha通道要清除)。

解決方法是使用不透明的上下文。

UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, 0.0); 
相關問題