python在不将模式从cmyk更改为rgb的情况下将.tif转换为.png
我想将.tif转换为.png。我找到的简单解决办法是python在不将模式从cmyk更改为rgb的情况下将.tif转换为.png,python,graphics,python-imaging-library,Python,Graphics,Python Imaging Library,我想将.tif转换为.png。我找到的简单解决办法是 import Image im = Image.open('39.tif') im.save('39.png') 这不起作用,给了我以下错误: Traceback (most recent call last): File "C:/Users/Marijus/Desktop/templates/rename.py", line 8, in <module> im.save('Foto.png') File "C
import Image
im = Image.open('39.tif')
im.save('39.png')
这不起作用,给了我以下错误:
Traceback (most recent call last):
File "C:/Users/Marijus/Desktop/templates/rename.py", line 8, in <module>
im.save('Foto.png')
File "C:\Python27\lib\site-packages\PIL\Image.py", line 1441, in save
save_handler(self, fp, filename)
File "C:\Python27\lib\site-packages\PIL\PngImagePlugin.py", line 506, in _save
raise IOError, "cannot write mode %s as PNG" % mode
IOError: cannot write mode CMYK as PNG
尽管它改变了颜色,但它还是起作用了。如何在不将模式从cmyk更改为rgb的情况下从.tif转换为.png?png文件只有索引模式、灰色模式、rgb模式和RGBA模式。这是文件格式,因此如果需要CMYK,请使用其他文件格式,例如TIF
if im.mode == "CMYK":
im = im.convert("RGB")