你能在pygame中使一个图像在另一个图像上透明吗?

发布于 2024-11-17 02:03:54 字数 171 浏览 5 评论 0原文

我可以在表面背景上使用 set_colorkey 方法和 convert_alpha 方法将图像设置为透明。但是,当我尝试重叠两个图像时,由于某种原因透明度会丢失。

所以重申一下,有没有办法使图像的一部分在另一个图像上透明(例如两个 png 或 gif 文件)

I'm able to set an image to be transparent using the both the set_colorkey method and the convert_alpha method over a surface background. However, when I try to overlap two images the transparency is lost for some reason.

So to reiterate, is there a way to make part of an image transparent over another image (e.g. two png or gif files)

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

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

发布评论

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

评论(1

以往的大感动 2024-11-24 02:03:54

我不确定您是否遇到了“错误”行为。颜色键 alpha 可能不支持您想要执行的操作,并且您可能定义了错误的像素数据,或者存在某种错误(视频驱动程序或 pygame)正在经历。

但我确实为您提供了解决方法:

http://www.pygame.org/文档/ref/surface.html

Pygame 支持三种类型的透明度:颜色键、表面 alpha 和像素 alpha

您可以尝试像素 alpha。它比颜色键 Alpha 更灵活,并且应该支持混合任意数量的图层。

您可以通过在创建表面时传递 SRCALPHA 来实现此目的,并确保您的输入像素数据具有正确定义的 Alpha 通道。

I'm not sure if you're running into "buggy" behavior or not. It is possible color-key alpha doesn't support what you are trying to do, and it is possible that you are either defining your pixel data wrong, or that there is some sort of bug (video driver or pygame) that you're experiencing.

But I do have a work-around for you:

http://www.pygame.org/docs/ref/surface.html

There are three types of transparency supported in Pygame: colorkeys, surface alphas, and pixel alphas

You could try pixel alphas. It will be more flexible than color-key alpha, and should support blending as many layers as you want.

You can do this by passing SRCALPHA when creating the surface, and ensuring that your input pixel data has a properly defined alpha channel.

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