2013-11-25 35 views
0

我有一个加载在UIImageView中的jpg图像,我尝试用灰度alpha蒙版图像来掩盖它。它只有一个灰度通道,没有RGB或alpha通道。为什么UIImageView忽略图像掩码?

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变体。没有什么能让它工作。

任何想法为什么?

+1

你尝试透明PNG?用黑色(alpha = 1)透明(alpha = 0)像素? – Cyrille

回答

-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];