Iphone 删除UIImageView中的白色背景
我正在使用Iphone 删除UIImageView中的白色背景,iphone,crop,transparent,uigraphicscontext,Iphone,Crop,Transparent,Uigraphicscontext,我正在使用UIBezierPath以白色背景和黑色笔划用手指和触摸端方法绘制线条。我正在使用cgraphicscontext()裁剪图像,效果很好。我想删除白色背景,使其透明。我已经尝试了几种代码,但这些代码对我不起作用。下面的代码使整个图像透明。除黑色笔划外,任何人都可以帮助我使图像透明。提前谢谢。对不起,如果问题已经被问到了 -(UIImage*) makeTransparent : (UIImage*) viewImage { CGImageRef rawImageRef = vi
UIBezierPath
以白色背景和黑色笔划用手指和触摸端方法绘制线条。我正在使用cgraphicscontext()
裁剪图像,效果很好。我想删除白色背景,使其透明。我已经尝试了几种代码,但这些代码对我不起作用。下面的代码使整个图像透明。除黑色笔划外,任何人都可以帮助我使图像透明。提前谢谢。对不起,如果问题已经被问到了
-(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;
}
您可以使用
UIImageView
来显示UIImage
,然后只需将BackgroundColor设置为clearColor
如下所示
[yourImageView setBackgroundColor:[UIColor clearColor]];
您可以使用
UIImageView
来显示UIImage
,然后只需将BackgroundColor设置为clearColor
如下所示
[yourImageView setBackgroundColor:[UIColor clearColor]];
很抱歉我的错误。裁剪时,我使用的是UIJPEG表示,而不是UIPNGRE表示。它解决了我的问题。对不起。我的错误。裁剪时,我使用的是UIJPEG表示,而不是UIPNGRE表示。它解决了我的问题。