[英]Converting grayscale png with transparency using PIL
PIL corrupt png images with transparency if i make them grayscale. 如果我把它们变成灰度,PIL会破坏png图像的透明度。 Why?
为什么?
Here's my code: 这是我的代码:
input = Image.open('input.png')
output = ImageOps.grayscale(input)
output.save('output.png', **input.info)
Input 输入
Output 产量
is there a way to fix that? 有没有办法解决这个问题?
您可以使用带亮度技巧的convert
方法:
Image.open('input.png').convert('LA').save('output.png')
I ran into this issue as well. 我也遇到过这个问题。 The only solution I've been able to find is to convert to 'LA' and then back to 'RGBA'
我能找到的唯一解决方案是转换为'LA'然后再转换回'RGBA'
Try: 尝试:
Image.open('input.png').convert('LA').convert('RGBA')
I was attempting to display the resulting grayscale PNG with transparency on a tkinter canvas, but I think this method will probably also work for saving the output. 我试图在tkinter画布上显示带有透明度的结果灰度PNG,但我认为这种方法可能也可用于保存输出。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.