【问题标题】:How to get the Difference blending mode?如何获得差异混合模式?
【发布时间】:2021-08-16 15:24:23
【问题描述】:

我正在尝试在 Pygame 中为我的游戏制作夜间效果。所以我要在屏幕上绘制一个黑色图像,然后将其混合模式更改为Difference,就像在 Photoshop 中一样,以使屏幕看起来更暗。但是,我仍然不知道该怎么做,因为我还没有使用 Pygame 中的混合模式。有什么帮助吗?

【问题讨论】:

    标签: python pygame color-blending


    【解决方案1】:

    混合模式可以通过设置pygame.Surface.blit的可选special_flags参数来改变:

    blit(source, dest, area=None, special_flags=0) -> Rect
    [...]
    pygame 1.8 中的新功能:可选的 special_flags:BLEND_ADDBLEND_SUBBLEND_MULTBLEND_MINBLEND_MAX
    pygame 1.8.1 中的新功能:可选的 special_flags:BLEND_RGBA_ADDBLEND_RGBA_SUBBLEND_RGBA_MULTBLEND_RGBA_MINBLEND_RGBA_MAXBLEND_RGB_ADDBLEND_RGB_SUBBLEND_RGB_MULTBLEND_RGB_MAX3。
    pygame 1.9.2 中的新功能:可选的 special_flags:BLEND_PREMULTIPLIED
    pygame 2.0.0 中的新功能:可选的 special_flags:BLEND_ALPHA_SDL2 [...]

    例如:

    screen.blit(image, (x, y), special_flags = pygame.BLEND_RGBA_SUB)
    

    不幸的是,Pygame 没有提供 2 张图像绝对差异的混合模式。但是它可以通过

    来实现

    MAX(SUB(image1, imgage2), SUB(image2, image1))

    例如:

    image1 = pygame.image.load('image2.png')
    image2 = pygame.image.load('image1.png')
    temp_image = image1.copy() 
    temp_image.blit(image2, (0, 0), special_flags = pygame.BLEND_RGBA_SUB)
    final_image = image2.copy() 
    final_image.blit(image1, (0, 0), special_flags = pygame.BLEND_RGBA_SUB)
    final_image.blit(temp_image, (0, 0), special_flags = pygame.BLEND_RGBA_MAX)
    

    【讨论】:

    • 谢谢,但这是否意味着差异模式不可用?
    • BLEND_RGBA_SUB 是你能得到的最接近的
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-02-03
    • 2020-12-27
    • 1970-01-01
    • 1970-01-01
    • 2020-05-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多