You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

为何Python Pillow 10.1.0可将RGB图转17色调色板,更少则失败?

Pillow 10.1.0自适应调色板转换异常问题

测试发现,无论使用哪张RGB图像,均可通过Python Pillow 10.1.0将其转换为17色自适应调色板(Adaptive Palette)图像,但转换为16色及以下时会触发报错:ValueError: conversion not supported

测试所用RGB图像

蓝黑渐变图

测试代码

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色调色板图像
img_P17.show()

# 转换为少于17色的调色板时出现异常:
img_P16 = img.convert('P', palette = Image.Palette.ADAPTIVE, colors = 16) # 16色调色板图像
img_P16.show() #ValueError: conversion not supported

相关对比图

17色与16色调色板转换对比图

内容的提问来源于stack exchange,提问作者user3382426

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.06 02:22:13