ImagePalette Module

The ImagePalette module contains a class of the same name to represent the color palette of palette mapped images.

注解

This module was never well-documented. It hasn’t changed since 2001, though, so it’s probably safe for you to read the source code and puzzle out the internals if you need to.

The ImagePalette class has several methods, but they are all marked as “experimental.” Read that as you will. The [source] link is there for a reason.

class PIL.ImagePalette.ImagePalette(mode='RGB', palette=None, size=0)[source]

Color palette for palette mapped images

getcolor(color)[source]

Given an rgb tuple, allocate palette entry.

警告

This method is experimental.

getdata()[source]

Get palette contents in format suitable # for the low-level im.putpalette primitive.

警告

This method is experimental.

save(fp)[source]

Save palette to text file.

警告

This method is experimental.

tobytes()[source]

Convert palette to bytes.

警告

This method is experimental.

tostring()

Convert palette to bytes.

警告

This method is experimental.

本页

帮助信息

你可以从IRC频道获取实时帮助: irc://irc.freenode.net#pil。你也可以使用邮件列表: Image-SIG mailing list。当然还可以去 Stack Overflow

如果你发现了Bug,可以去 Github提交issues。