提问人:user3382426 提问时间:11/17/2023 最后编辑:user3382426 更新时间:11/18/2023 访问量:53
为什么我可以将 RGB 图像转换为 17 个调色板,但不能更少?(Python Pillow 版本 10.1.0)
Why can I convert an RGB image to a 17 color palette, but no fewer? (Python Pillow version 10.1.0)
问:
import numpy as np
import PIL
from PIL import Image
img = Image.open('sigh.png')
img_P17 = img.convert('P', palette = Image.Palette.ADAPTIVE, colors = 17) # 17 color palettized image
img_P17.show()
# Fewer than 17 color palette conversion not working for some reason:
img_P16 = img.convert('P', palette = Image.Palette.ADAPTIVE, colors = 16) # 16 color palettized image
img_P16.show() #ValueError: conversion not supported
答: 暂无答案
评论
print(img.mode)
img_P16.save('foo.png')
img_P16.save('foo.png', save_all=True)