【问题标题】:Why does UIImageView ignore the image mask?为什么 UIImageView 会忽略图像遮罩?
【发布时间】:2013-11-25 12:14:09
【问题描述】:

我在 UIImageView 中加载了 jpg 图像,并尝试使用灰度 alpha 蒙版图像对其进行蒙版。它只有一个灰度通道,没有 RGB 或 Alpha 通道。

iv = [UIImage imageNamed:@"image.jpg"];
self.foreground = iv;

CALayer *mask = [CALayer layer];
UIImage *maskImg = [UIImage imageNamed:@"mask.jpg"];
mask.contents = (id)[maskImg CGImage];
mask.frame = iv.bounds;

iv.layer.mask = mask;
iv.layer.masksToBounds = YES;

[self addSubview:iv];

图像已正确加载。但是面膜完全没有效果。我尝试在 Photoshop 中将其反转,并尝试将其保存为各种其他文件格式,包括所有类型的 PNG 变体。没有什么可以让它发挥作用。

知道为什么吗?

【问题讨论】:

  • 你试过透明PNG吗?用黑色(alpha = 1)到透明(alpha = 0)像素?

标签: ios iphone ipad calayer


【解决方案1】:

将此代码用于图像屏蔽...

YourImageview.layer.borderWidth=1.0;
YourImageview.layer.borderColor = [UIColor lightGrayColor].CGColor;
YourImageview.layer.backgroundColor=[UIColor whiteColor].CGColor;
YourImageview.layer.cornerRadius=30.5;
[YourImageview.layer setMasksToBounds:YES];

【讨论】:

    猜你喜欢
    • 2021-01-02
    • 2011-12-30
    • 1970-01-01
    • 2022-10-23
    • 2018-09-18
    • 2018-05-29
    • 2016-06-09
    • 2016-01-07
    • 1970-01-01
    相关资源
    最近更新 更多