使用win32api中e的SaveBitmapFilez方法只能将PyCBitmap保存为BMP文件,一张1920*1080的图像接近8M大小,请问如何压缩成jpg格式的图片呢?
使用win32api中e的SaveBitmapFilez方法只能将PyCBitmap保存为BMP文件,一张1920*1080的图像接近8M大小,请问如何压缩成jpg格式的图片呢?
import os
from PIL import Image
for root, dirs, files in os.walk("."):
for bmpfig in files:
if not bmpfig.endswith('.bmp') and not bmpfig.endswith('.png'):
continue
bmpfig = os.path.join(root, bmpfig)
newfigname = bmpfig[:-4] + ".jpg"
print "converting from", bmpfig, "to", newfigname
img = Image.open(bmpfig)
img = img.convert('RGB') # for png
img.save(newfigname, format='jpeg', quality=95)
img.close()
os.remove(bmpfig)