python - 如何将 PIL ImageDraw 转换为 Image

标签 python python-imaging-library

我有一张 PIL 图片:

img=Image.open(...)

我将其转换为 ImageDraw 以在其中写入。

img=ImageDraw.Draw(img)

现在我把文字放进去:

img.text((0,0), 'text', (0,0,0))

现在我想要它恢复为图像

我希望是这样的:

img = Image.fromdraw(img)

我需要这种格式的图像,以便进一步处理。

我该怎么做?

最佳答案

ImageDraw绘制在您的原始图像上,因此您应该将两个实例(Image 和 ImageDraw 对象)保存在单独的变量中。

img = Image.open(...)
draw = ImageDraw.Draw(img)
draw.text((0,0), 'text', (0,0,0))
# img is modified inplace

关于python - 如何将 PIL ImageDraw 转换为 Image,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/68070114/

相关文章:

python - xcode 可以附加和调试从 c 应用程序运行的 python 吗?

python - 在Python中的图像上大纲文本

python - PIL Image 从 numpy 数组构造奇怪的图像 - 为什么?

python - 如何使用 type() 创建绑定(bind)方法?

python - 将一行中所有字符的总和返回到另一列 pandas

python - 用 Pillow 阅读的 Gif 有黑色边框

python - 使用 Python(没有 SciPy)检测照片中的特定水印

python - 使用 Pillow 在 Python 中将数组转换为图像 (tif)

python - 如何使用 scipy 的 affine_transform 对彩色图像进行任意仿射变换?

python - 如何测试调用socket.send时是否引发异常