I've got a UIImage which is generated as a screenshot. I'm adding this object with the following code:
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];
However my Image only turns white, and I'd like to have the image to be transparent on the places where it's white by using CGImageCreateMaskingColors.
Hope someone can help me out.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…