2

如何在 python 中用另一种颜色替换多个图像中的颜色?我有一个包含 400 个精灵动画的文件夹。我想将块色阴影(111,79,51)更改为具有 alpha 透明度的阴影。我可以使用以下方法轻松进行批量转换:

img = glob.glob(filepath\*.bmp)

但是我不知道如何更改像素颜色。如果有任何区别,图像都是 96x96,我不在乎这个过程需要多长时间。我正在使用 python 3.2.2,所以我不能真正使用 PIL(我认为)

4

2 回答 2

0

Are your images in indexed mode (8 bit per pixel with a palette),or "truecolor" 32bpp images? If they are in indexed modes, it would not be hard to simply mark the palette entry for that color to be transparent across all files.

Otherwise, you will really have to process all pixel data. It also could be done by writting a Python script for GIMP - but that would require Python-2 nonetheless.

于 2012-05-21T14:41:35.370 回答
0

BMP 是一种 windows 文件格式,所以你需要 PIL 或类似的东西;或者您可以推出自己的阅读器/作家。据我所知,基本模块无济于事。您可以使用作为标准分发的一部分的 Tk (PhotoImage()) 读取 PPM 和 GIF,并在该图像上使用 get() 和 put() 来更改像素值。请参阅在线参考,因为它不是直截了当的 - 像素来自 get() 作为 3 元组整数,但需要返回 put() 作为空格分隔的十六进制文本!

于 2012-05-21T11:19:06.427 回答