2
我有一个生成为截图的UIImage。我加入这个对象用下面的代码:如何将UIImage中的颜色“白色”更改为透明
self.view.backgroundColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:0.0];
drawImage.backgroundColor = [UIColor colorWithRed:1 green:1 blue:1 alpha:0.0];
UIGraphicsBeginImageContext(self.view.bounds.size);
[drawImage.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
CGImageRef rawImageRef=viewImage.CGImage;
const float colorMasking[6] = {255,255,255,255,0,0};
CGImageCreateWithMaskingColors(rawImageRef, colorMasking);
UIImage *newImage = [UIImage imageWithCGImage:rawImageRef];
但是我的图片仅为变白了,我想有图像出现在哪里这是通过使用CGImageCreateMaskingColors白色的地方是透明的。
希望有人能帮助我。
你的函数可以工作,但是我在边缘有一个非常模糊的结果。 – BarryK88 2012-02-27 21:53:27
我不确定什么花费模糊的结果。你能在这里发布结果图吗?也许你可以尝试调整颜色掩饰,例如{225,255,225,255,225,255}。 – tommyli 2012-02-28 02:26:18
的结果是,当将transparant视图的图像保存到文档目录时,我的背景变为白色。所以可能会导致边缘模糊效果。 – BarryK88 2012-02-29 09:46:04