基本上,我正在制作一个包含两个图像的视图。图一显示在视图左上角的右三角形中,图二显示右上三角形,右下角。
想象一个对角线切割的正方形,每一半都有不同的图像。
我读了很多关于面具的文章,但我不想用另一张图片来遮罩这些图片。
我正在寻找一种方法来给它3个点,形成那个三角形,然后让它以这种方式裁剪图像。
我觉得这在Coregraphics中可能很容易做到,我只是错过了我认为的调用。
任何帮助都是非常感谢的!
发布于 2012-12-26 06:18:16
这里有一种方法,在图像上下文中使用裁剪路径。该示例是针对256x256的图像大小的,但是您应该能够很容易地使其适应您的需要。
UIGraphicsBeginImageContext(CGSizeMake(256, 256));
CGContextRef context = UIGraphicsGetCurrentContext();
CGAffineTransform flipVertical = CGAffineTransformMake(1, 0, 0, -1, 0, 256);
CGContextConcatCTM(context, flipVertical);
CGContextBeginPath(context);
CGContextMoveToPoint(context, 0, 0);
CGContextAddLineToPoint(context, 0, 256);
CGContextAddLineToPoint(context, 256, 256);
CGContextClosePath(context);
CGContextSaveGState(context);
CGContextClip(context);
CGContextDrawImage(context, CGRectMake(0, 0, 256, 256), [image1 CGImage]);
CGContextRestoreGState(context);
CGContextBeginPath(context);
CGContextMoveToPoint(context, 0, 0);
CGContextAddLineToPoint(context, 256, 0);
CGContextAddLineToPoint(context, 256, 256);
CGContextClosePath(context);
CGContextSaveGState(context);
CGContextClip(context);
CGContextDrawImage(context, CGRectMake(0, 0, 256, 256), [image2 CGImage]);
CGContextRestoreGState(context);
UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); // image contains the result
UIGraphicsEndImageContext();https://stackoverflow.com/questions/14033945
复制相似问题