Is it possible to reduce an image's depth using PIL?
Is it possible to开发者_如何学C reduce the depth of an image using PIL? Say like going to 4bpp from a regular 8bpp.
You can easily convert image modes (just call im.convert(newmode)
on an image object im
, it will give you a new image of the new required mode), but there's no mode for "4bpp"; the modes supported are listed here in the The Python Imaging Library Handbook.
This can be done using the changeColorDepth function in ufp.image module. this function only can reduce color depth(bpp)
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')
精彩评论