首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Pygame变换图像的色调

Pygame变换图像的色调
EN

Stack Overflow用户
提问于 2015-06-14 15:19:19
回答 2查看 1.3K关注 0票数 1

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

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

EN

回答 2

Stack Overflow用户

发布于 2015-06-15 23:46:16

您可以使用Python PIL来完成此操作。看看这个问题和答案,特别是他们链接的原始问题和答案:

Changing the color of an image based on RGB value

票数 0
EN

Stack Overflow用户

发布于 2022-01-26 16:11:39

代码语言:javascript
复制
    '''
    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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30826897

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档