pygame中的混合模式是什么意思?
Surface.blit 在 1.8 中有一个新参数:混合。 定义了以下值:
BLEND_ADD
BLEND_SUB
BLEND_MULT
BLEND_MIN
BLEND_MAX
BLEND_RGBA_ADD
BLEND_RGBA_SUB
BLEND_RGBA_MULT
BLEND_RGBA_MIN
BLEND_RGBA_MAX
BLEND_RGB_ADD
BLEND_RGB_SUB
code>BLEND_RGB_MULT
BLEND_RGB_MIN
BLEND_RGB_MAX
有人能解释一下这些模式的含义吗?
Surface.blit has a new parameter in 1.8: blend. The following values are defined:
BLEND_ADD
BLEND_SUB
BLEND_MULT
BLEND_MIN
BLEND_MAX
BLEND_RGBA_ADD
BLEND_RGBA_SUB
BLEND_RGBA_MULT
BLEND_RGBA_MIN
BLEND_RGBA_MAX
BLEND_RGB_ADD
BLEND_RGB_SUB
BLEND_RGB_MULT
BLEND_RGB_MIN
BLEND_RGB_MAX
Can someone explain what these modes mean?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在此处找到混合操作的源代码:surface.h
基本上,ADD 将两个源像素相加并将结果剪辑为 255。SUB 将两个像素相减并将结果剪辑为 0。
MULT
:结果 = (p1 * p2) / 256
MIN
:选择每个通道的较低值(不是整个像素),因此如果pixel1为(100,10,0)
,pixel2为(0 ,10,100)
,您将得到(0,10,0)
MAX
:与 MIN 相反(即(100,10,100)
)还有一个附加的混合模式,从文档中并不明显:
0
(或者只是忽略该参数)。 此模式会将源表面“标记”到目标表面。 如果源表面有 Alpha 通道,这将决定每个像素的“强度”(0
=无效果,255
=复制像素,128< /code>:
结果 = .5*源 + .5*目的地
)。有用的效果:要使某个区域变暗,请使用混合模式 0,将源/图章表面填充为黑色并将 alpha 设置为
10
:(0,0,0,10)
。要使其变亮,请使用白色
(255,255,255,10)
。You can find the source for the blend operations here: surface.h
Basically, ADD adds the two source pixels and clips the result at 255. SUB subtracts the two pixels and clips at 0.
MULT
:result = (p1 * p2) / 256
MIN
: Select the lower value of each channel (not the whole pixel), so if pixel1 is(100,10,0)
and pixel2 is(0,10,100)
, you get(0,10,0)
MAX
: Opposite of MIN (i.e.(100,10,100)
)And there is an additional blend mode which isn't obvious from the docs:
0
(or just leave the parameter out). This mode will "stamp" source surface into the destination. If the source surface has an alpha channel, this will be determine how "strong" each pixel is (0
=no effect,255
=copy pixel,128
:result = .5*source + .5*destination
).Useful effects: To darken a certain area, use blend mode 0, fill the source/stamp surface black and set alpha to
10
:(0,0,0,10)
.To lighten it, use white
(255,255,255,10)
.这些是用于将图像相互叠加的混合模式。 混合模式的名称已经告诉您底层操作。
BLEND_*
常量只是BLEND_RGB_*
常量的别名,而BLEND_RGBA_*
变体在所有四个通道(包括 Alpha 通道)上运行,如下所示与仅 RGB 相对。有关不同混合模式及其各自效果的一般信息,请参阅此处。
Those are blending modes for compositing images on top of each other. The name of the blending mode already tells you the underlying operation.
The
BLEND_*
constants are simply aliases for theBLEND_RGB_*
constants and theBLEND_RGBA_*
variants operate on all four channels (including the alpha channel) as opposed to only RGB.For general information about the different blending modes and their respective effects, see here.