我有一个关于Python模块pygame的问题。
我想要更改精灵图像的色调,就像对图像应用滤镜一样。我看过许多关于将特定像素从一种颜色更改为另一种颜色的帖子,尽管这不是我想要做的。我想做一些类似于在paint.net等简单的照片编辑软件中可以做的事情,改变图像的整体颜色。我当然可以在照片编辑软件中改变图像的色调,但这会导致需要制作、加载和管理大量图像,这很快就会变得非常繁琐。我希望有一种方法可以改变pygame中图像的色调。
发布于 2015-06-15 23:46:16
您可以使用Python PIL来完成此操作。看看这个问题和答案,特别是他们链接的原始问题和答案:
发布于 2022-01-26 16:11:39
'''
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 grepperhttps://stackoverflow.com/questions/30826897
复制相似问题