我可以在 UIImageView 中编辑 UIImage 的 Alpha Mask,而不必移动太多内存吗?
我想拍摄一个图像(画笔)并将其绘制到显示的图像中。我只想影响该图像的 Alpha,并且需要稍后将其导出。
据我所知,大多数方向实际上只是进行了一些看起来成本高昂但不会成功的操作。即,他们建议您绘制到屏幕外上下文中,创建遮罩的 CGImage,并在每次应用画笔时创建 CGImageWithMask。
我已经知道这代价高昂,因为对于 iPhone 来说,即使只是这样做并绘制到上下文中也是相当粗糙的。
我想做的是获取 UIImageView 的 UIImage,并直接操作它的 Alpha 通道。我也不是逐个像素地进行操作,而是使用具有自身柔软度的较大(20px 半径)画笔。
I want to take a image (a brush) and draw it into a displayed image. I only want to affect the alpha of that image, and I need to export it later.
From what I've seen, most directions only really get into some costly looking operations that don't pan out. ie they recommend you draw into an offscreen context, create a CGImage of the mask, and create a CGImageWithMask pretty much every time the brush is applied at all.
I already know this is costly because even just doing this and drawing into a context is rather rough for iPhone.
What I'd like to do is take the UIImage of an UIImageView, and manipulate it's alpha channel directly. I also am not doing it pixel-by-pixel, but with a largish (20px radius) brush that has a softness of its own.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不会为此使用 UIImageView。一个普通的 UIView 就足够了。
只需将图像放入图层中,
然后您可以通过向图层添加蒙版
来使图像的某些部分透明,我做了一个项目,其中我有一个 Brush.png,您可以用它来用手指显示图像。 ..我的更新掩码功能是:
I would not use an UIImageView for this. A normal UIView is enough.
Just put the Image into the layer with
after that you can make parts of the image transparent by adding a mask to the layer
for a project I did something where I had a brush.png that you could use to reveal an image with a finger... my update mask function there was: