在 Pygame 中为图像着色 [英] Tinting an image in Pygame

查看:44
本文介绍了在 Pygame 中为图像着色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究如何以与 Monogame 类似的方式在 Pygame 中为图像着色.我一直在尝试让像 BLEND_ADD 这样的自定义标志起作用,但很难找到我正在寻找的简洁示例,主要是人们试图以某种方式变暗"或使用 alpha 级别.

问题:如何以与 MonoGame 相同的方式将图像着色为特定的 RGBA 值?

解决方案

用一种颜色填充你的图像并传递一个

I'm looking on how to tint an image in Pygame in a similar fashion of how Monogame does it. I've been trying to get custom flags like BLEND_ADD to work but it's been hard to find concise examples of what I'm looking for, it's mostly been people trying to "darken" or work with the alpha levels in a way.

Question: How do I tint an image to a certain RGBA value in the same way that MonoGame does it?

解决方案

Fill your image with a color and pass one of the BLEND constants as the special_flags argument, e.g. your_image.fill((190, 0, 0, 100), special_flags=pygame.BLEND_ADD).

Note that BLEND_RGB_ADD is just an alias for BLEND_ADD (and the same applies to the other modes). The RGBA modes will also modify the alpha channel (ADD and MAX make transparent parts visible).

Here's a table that shows you the effects of the different blending modes (I've also added the names of the modes in Photoshop):

这篇关于在 Pygame 中为图像着色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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