更改像素颜色Python

更改像素颜色Python,第1张

更改像素颜色Python

假设您正在尝试使用该

Image
模块。这是一个例子:

from PIL import Imagepicture = Image.open("/path/to/my/picture.jpg")r,g,b = picture.getpixel( (0,0) )print("Red: {0}, Green: {1}, Blue: {2}".format(r,g,b))

在此图像上运行此命令,得到输出:

>>> from PIL import Image>>> picture = Image.open("/home/gizmo/Downloads/image_launch_a5.jpg")>>> r,g,b = picture.getpixel( (0,0) )>>> print("Red: {0}, Green: {1}, Blue: {2}".format(r,g,b))Red: 138, Green: 161, Blue: 175

编辑:做你想要的我会尝试这样的事情

from PIL import Imagepicture = Image.open("/path/to/my/picture.jpg")# Get the size of the imagewidth, height = picture.size()# Process every pixelfor x in width:   for y in height:       current_color = picture.getpixel( (x,y) )       ####################################################################       # Do your logic here and create a new (R,G,B) tuple called new_color       ####################################################################       picture.putpixel( (x,y), new_color)


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5629530.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-15
下一篇 2022-12-15

发表评论

登录后才能评论

评论列表(0条)

保存