IOS:仅对透明像素着色
<p><p>如果我有一个带有一些透明像素的图像,是否有可能用白色为透明像素着色并在objective-c 中使图像的其余部分透明? </p>
<p>谢谢!</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>我找到了解决办法:</p>
<pre><code>- (UIImage*)convertToInverseWhiteMask: (UIImage *) image {
UIGraphicsBeginImageContextWithOptions(image.size, NO, image.scale);
CGRect imageRect = CGRectMake(0.0f, 0.0f, image.size.width, image.size.height);
CGContextRef ctx = UIGraphicsGetCurrentContext();
// Draw a white background (for white mask)
CGContextSetRGBFillColor(ctx, 1.0f, 1.0f, 1.0f, 1.0f);
CGContextFillRect(ctx, imageRect);
// Apply the source image's alpha
;
UIImage* mask = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return mask;
}
</code></pre></p>
<p style="font-size: 20px;">关于IOS:仅对透明像素着色,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/19139461/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/19139461/
</a>
</p>
页:
[1]