创建浮点颜色

2024-09-28 22:13:13 发布

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

在 我想用浮点颜色绘制一个像素,例如rgb(173.373,216,230) 我尝试使用枕头图像和图像颜色,但没有成功

我的主要目标是能够读写图像中的浮点颜色。在

from PIL import Image, ImageColor

im = Image.new("RGB", (32, 32), ImageColor.getrgb("rgb(173.373, 216, 230)"))

im.save('simplePixel.png')

在 但我得到了以下错误:

^{pr2}$

Tags: from图像imageimport目标newpil颜色
1条回答
网友
1楼 · 发布于 2024-09-28 22:13:13

正如保利所说,没有这种“层次”的颜色。不能在颜色字符串中使用浮动。在

文件规定:

RGB functions, given as rgb(red, green, blue) where the color values are integers in the range 0 to 255. Alternatively, the color values can be given as three percentages (0% to 100%). For example, rgb(255,0,0) and rgb(100%,0%,0%) both specify pure red.

所以这些是你唯一可以使用的选项。在

相关问题 更多 >