python - PIL选择坐标来制作图像

标签 python image python-imaging-library

我想根据我所选择的坐标创建图像。所以我希望每个坐标都设置为特定的大小和颜色,例如黑色和 2X2,然后将其放置在它代表的特定像素处。 我将如何处理这件事? 函数 putpixel 可以实现我想要做的事情吗?

提前致谢

最佳答案

使用 putpixel 执行此操作会很不方便,但并非不可能。既然你说你想要制作多个像素的点,那么最好使用 ImageDraw.rectangle()或用 ellipse() 代替。

例如:

import Image
import ImageDraw

img = Image.new("RGB", (400,400), "white")
draw = ImageDraw.Draw(img)

coords = [(100,70), (220, 310), (200,200)]
dotSize = 2

for (x,y) in coords:
    draw.rectangle([x,y,x+dotSize-1,y+dotSize-1], fill="black")

img.show()

关于python - PIL选择坐标来制作图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14831248/

相关文章:

Python PIL -> 居中长文本

python - 在 Kivy Canvas 上显示 PIL 图片

python - 类型错误 : Object of type X is not JSON serializable

python - 使用 pip 升级最初通过 apt 安装的包

node.js - 无法在 Node js中显示静态文件夹中的图像

image - 图像集合内的音频集合

python - matplotlib 图形中的白色到透明层 (SVG)

python - AttributeError : cffi library '(pyModulesPath)\_soundfile_data\libsndfile64bit.dll' has no function, 常量或名为 'sf_wchar_open' 的全局变量

python - 在数据框数据上调用函数

javascript - CSS/JS 切换简单产品图库的缩略图不透明度