我正在使用UIBezierPath
手指在白色背景和黑色笔划中绘制线条,并且使用我正在裁剪图像的触摸结束方法CGGraphicsContext()
,并且效果很好。我想删除白色背景并使其透明。我尝试了几个代码,但对我不起作用。下面的代码使整个图像透明。除黑色笔触外,任何人都可以帮助我使图像透明。提前致谢。对不起,如果问题已经被问到。
-(UIImage*) makeTransparent : (UIImage*) viewImage
{
CGImageRef rawImageRef = viewImage.CGImage;
const float colorMasking[6] = {255, 255, 255, 255, 255, 255};
UIGraphicsBeginImageContext(viewImage.size);
CGImageRef maskedImageRef = CGImageCreateWithMaskingColors(rawImageRef, colorMasking);
CGContextTranslateCTM(UIGraphicsGetCurrentContext(), 0.0, viewImage.size.height);
CGContextScaleCTM(UIGraphicsGetCurrentContext(), 1.0, -1.0);
CGContextDrawImage(UIGraphicsGetCurrentContext(), CGRectMake(0, 0, viewImage.size.width, viewImage.size.height), maskedImageRef);
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
CGImageRelease(maskedImageRef);
UIGraphicsEndImageContext();
return newImage;
}