使用 Python 代码选择/更改照片区域的颜色和图案

2024-04-25 20:55:40 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在寻找一些关于如何编写一段代码(首选python)的指导,以将此图片上counte top的颜色/图案更改为用户将选择的其他颜色/图案。我正在查看python PIL,但找不到选择/粘贴的方法 图片中的新图案。非常感谢你的帮助。非常感谢。你知道吗

before

after


Tags: 方法代码用户pil颜色粘贴top图片
1条回答
网友
1楼 · 发布于 2024-04-25 20:55:40

您将需要使用Image模块来完成您想要完成的任务。你知道吗

import Image
picture = Image.open("/path/of/your/picture.jpg")

# Get the dimensions of your picture
width, height = picture.size()

# Process the pixels you are focused on
for x in width:
   for y in height:
       current_color = picture.getpixel( (x,y) )
       ####################################################################
       #create a new (R,G,B) tuple called new_color
       ####################################################################
       picture.putpixel( (x,y), new_color)

相关问题 更多 >