开发者

Is it possible to reduce an image's depth using PIL?

开发者 https://www.devze.com 2022-12-08 06:09 出处:网络
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

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')
0

精彩评论

暂无评论...
验证码 换一张
取 消