如何在太平船务的 putpixel 中使用灰度颜色?



我需要一个函数来为 0 创建最白的值,为 1 创建最黑的值(所有其他值,如 0.5,都是一些灰色调(放入putpixel但我不知道该怎么做。

value = Greyscale(0.5) #or any other in the range of 0 and 1.
Image.putpixel((X, Y), (value))

我该如何实现?还是已经有一个功能?我搜索了文档,但找不到任何有用的东西。

根据 L 类型图像的位深度,值范围从 0 到 255,深度为 8。

对于 8 位深度,函数如下所示:

def inverted_grayscale(v): 
    return int((1 - v) * 255)

最新更新