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