繁体   English   中英

Pygame 改变图像的色调

[英]Pygame Changing Hue of Image

我有一个关于 Python 模块 pygame 的问题。

我想更改精灵图像的色调,例如对图像应用滤镜。 我看过很多关于将特定像素从一种颜色更改为另一种颜色的帖子,尽管这不是我想做的。 我想做一些类似于在简单的照片编辑软件(如paint.net)中可以做的事情,改变图像的整体颜色。 我当然可以在照片编辑软件中更改图像的色调,但这会导致需要制作、加载和管理大量图像,很快就会变得非常乏味。 我希望有某种方法可以改变 pygame 中图像的色调。

您可以使用Python PIL执行此操作。 看一下这个问题和答案,尤其是它们链接到的原始问题和答案:

https://stackoverflow.com/questions/11832055/changing-the-color-of-an-image-based-on-rgb-value

    '''
    Original post https://www.reddit.com/r/pygame/comments/hprkpr/how_to_change_the_color_of_an_image_in_pygame/
    '''
    
blue_rgb = (0,0,255) red_rgb = (255,0,0) img =
pygame.image.load("sky_picture.png") # loads the picture from the path
given var = pygame.PixelArray(img)
# var.replace(([Colour you want to replace]), [Colour you want]) var.replace((blue_rgb), (red_rgb)) # replaces all blue in the picture
to red del var 
"""
if the picture has some unchanged pixels left it's probably because they are not EXACTLY the rgb given for example (254,0,0) is not
(255,0,0) and won't be changed (to fix this you will have to calculate
the approx number ot just change the main picture)
"""  
# I also uploaded this to grepper

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM