擅长:python、mysql、java
<p>这可以使用<strong>ufp.image</strong>模块中的<strong>changeColorDepth</strong>函数来完成。
此函数只能减少颜色深度(bpp)</p>
<pre><code>import ufp.image
import PIL
im = PIL.Image.open('test.png')
ufp.image.changeColorDepth(im, 16) # change to 4bpp(this function change original PIL.Image object)
im.save('changed.png')
</code></pre>
<p>参见示例:<a href="http://runnable.com/VQ5o_OpMIyQdA6zE/image-quantize-by-improved-gray-scale-for-python" rel="nofollow"> image quantize by Improved Gray Scale. [Python] </a></p>