UIImage 边缘的 Alpha 混合

发布于 2024-10-21 07:13:45 字数 450 浏览 6 评论 0原文

我有两张矩形图像:一张是前景,另一张是背景。我试图混合前景图像的边缘,使前景图像看起来像是背景图像的“一部分”。换句话说,我试图应用透明效果,前景图像的不透明度从图像中心的 100% 降至边缘的 0%。我发现此操作有时有不同的名称,例如:Alpha 合成、Alpha 混合、边缘羽化或边缘透明度。以下是我试图获得的效果的更详细描述: http://en.wikipedia.org/ wiki/Alpha_compositing

我已经查看了 CGContext 文档,但我还没有找到任何可以开箱即用的函数。

有没有办法使用 CGContext 甚至 OpenGL 来做到这一点?有没有办法在非矩形图像上做到这一点?我知道,所有图像都是矩形的,但我的意思是一个图像,其中有一个圆圈,周围有一个透明区域。

I have two rectangular images: one is foreground, the other one is background. I am trying to blend the edges of the foreground image so that the foreground image looks like it is "part" of the background image. In other words, I am trying to apply a transparency effect, with the opacity of the foreground image decreasing from 100% at the center of the image down to 0% at the edges. I have found that this operation is sometimes referred by different names, such as: alpha compositing, alpha blending, edge feathering or edge transparency. Here is a more detailed description of the effect I am trying to obtain: http://en.wikipedia.org/wiki/Alpha_compositing

I have looked at the CGContext documentation, but I haven't found any function that would do that out of the box.

Is there any way to do that using CGContext or even OpenGL? Would there be a way to do it on a non-rectangular image? I know, all images are rectangular, but I mean an image with let's say, a circle in it, and a transparent area all around.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白衬杉格子梦 2024-10-28 07:13:45

iOS 库中的 CGImageCreateWithMask() 函数可以进行 Alpha 混合,同时降低边缘的不透明度。通过组合这两个链接中的代码可以让某些东西起作用:

http://iosdevelopertips.com/cocoa/how-to-mask-an-image.html

使用 CGImageMaskCreate 创建蒙版是全黑的 (iphone)

蒙版中每个像素的灰色级别(从黑到白)将定义混合过程中的不透明度级别。

The CGImageCreateWithMask() function in the iOS library can do alpha blending with decreasing opacity on the edges. It's possible to get something to work by combining the code in these two links:

http://iosdevelopertips.com/cocoa/how-to-mask-an-image.html

Creating mask with CGImageMaskCreate is all black (iphone)

The level of gray (from black to white) of each pixel in the mask will define the level of opacity during blending.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文