iphone - 如何在 ios 中创建自己的面具

标签 iphone ios uiimage masking

enter image description here

Duplicate

所以不要诋毁我的名声。

我的蒙版图像是: enter image description here

我的输出是:enter image description here

- (UIImage*)maskImage:(UIImage *)image withMask:(UIImage *)maskImage {

    CGImageRef maskRef = maskImage.CGImage;

    CGImageRef mask = CGImageMaskCreate(
                                        CGImageGetWidth(maskRef),
                                        CGImageGetHeight(maskRef),
                                        CGImageGetBitsPerComponent(maskRef),
                                        CGImageGetBitsPerPixel(maskRef),
                                        CGImageGetBytesPerRow(maskRef),
                                        CGImageGetDataProvider(maskRef), NULL, false
                                        );

    CGImageRef masked = CGImageCreateWithMask(image.CGImage, mask);
    CGImageRelease(mask);
    return [UIImage imageWithCGImage:masked];
}

那么如何创建自己的 mask 图像呢?

谢谢...

最佳答案

尝试将图像转换为没有 alpha 的灰度图像。

  • 将其另存为 .jpg 以去除 alpha。然后你可以将它保存回png。 此图片应该已经可以使用了。

  • 通过 image->mode->greyscale 将其转换为灰度(因为颜色信息在这种掩蔽中被丢弃)。

enter image description here

关于iphone - 如何在 ios 中创建自己的面具,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10992290/

相关文章:

ios - Swift 出错,需要帮助 : property 'self.circle1' not initialized at super. 初始化调用

ios - 如何从古吉拉特语(其他语言)的 ios 字符串中获取单个字符

ios - 如何快速更改标签栏未选中图标的颜色?

iphone - UISearchbar 取消按钮的图像

ios - 如何加载图像到uiimageview

iphone - 重新加载没有动画的 UITableView

iphone - 应用程序在 super dealloc 方法中崩溃

Android/iOS 移动浏览器 - 禁用事件

ios - 如何在没有 Storyboard 的情况下在 UITableViewRowAction 中自定义字体和颜色

ios - 将 PFFile 转换为 UIImage