如何使用遮罩层拍摄快照? [英] How to take a layer's snapshot with mask layer?

查看:71
本文介绍了如何使用遮罩层拍摄快照?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在UIView的图层上添加了一个蒙版:

I added a mask to UIView's layer:

CGImageRef maskImageRef = [UIImage imageNamed:"Icon.png"].CGImage; 
CALayer maskLayer = [CALayer layer];
maskLayer.contents = (__bridge id)maskImageRef;
self.layer.mask = maskLayer;

然后我使用以下代码从UIView获取快照:

Then I use this code to get snapshot from a UIView:

[self.layer renderInContext:mainViewContentContext];

但未绘制蒙版。

如何用面膜绘制self.layer?

How to draw self.layer with mask?

特殊提示!

推荐答案

一种解决方法是使用石英函数

One way to fix this can be to use Quartz functions

在drawRect方法中使用CGContextClipToMask(context,rect,maskImage)

Use CGContextClipToMask(context, rect, maskImage) inside drawRect method

请参阅 CGContextClipToMask示例链接以获取帮助

这篇关于如何使用遮罩层拍摄快照?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆