【发布时间】:2012-07-05 10:55:59
【问题描述】:
我在创建不规则形状的图像时遇到问题。这是我的框架示例。
请提供任何想法来创建这样的图像。它包含两个不同帧中的两个图像。但是这两张图片在装入框架后都隐藏了一部分。
【问题讨论】:
-
解决方案是你必须将图像框架作为图像,中心透明,并将实际图像放在后面
标签: iphone ios5 photolibrary
我在创建不规则形状的图像时遇到问题。这是我的框架示例。
请提供任何想法来创建这样的图像。它包含两个不同帧中的两个图像。但是这两张图片在装入框架后都隐藏了一部分。
【问题讨论】:
标签: iphone ios5 photolibrary
您必须创建遮罩图像,以遮盖原始图像的一部分。 试试看How to Mask an UIImageView 可能会有所帮助...
【讨论】:
你可以使用面具:
- (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);
return [UIImage imageWithCGImage:masked];
}
【讨论】:
你需要有边框的图像来掩盖你的 imagview 的图像。现在这样做:
#import <QuartzCore/QuartzCore.h>
// remember to include Framework as well
CALayer *mask = [CALayer layer];
mask.contents = (id)[[UIImage imageNamed:@"bordered_image_mask.png"] CGImage]; // here bordered image
mask.frame = CGRectMake(5, 5, <img_width>, <img_height>); // here x and y is 5 to show white boder around like in image
yourImageView.layer.mask = mask;
yourImageView.layer.masksToBounds = YES;
【讨论】: