我在使用PIL的裁剪函数时遇到了一个可能非常基础的问题:裁剪后的图像颜色完全失真。以下是代码:
>>> from PIL import Image
>>> img = Image.open('football.jpg')
>>> img
<PIL.JpegImagePlugin.JpegImageFile instance at 0x00
>>> img.format
'JPEG'
>>> img.mode
'RGB'
>>> box = (120,190,400,415)
>>> area = img.crop(box)
>>> area
<PIL.Image._ImageCrop instance at 0x00D56328>
>>> area.format
>>> area.mode
'RGB'
>>> output = open('cropped_football.jpg', 'w')
>>> area.save(output)
>>> output.close()
原始图片:
![在此输入图片描述](https://istack.dev59.com/xJCt3.webp)
感谢您的帮助!
-Hoff