我试图用python中的pillow模块打开一个图像

2024-10-03 00:16:31 发布

您现在位置:Python中文网/ 问答频道 /正文

from PIL import Image

image1 = Image.open('img1.jpg', "rb")
image1.show()

使用此命令

我得到了下面的错误,我试图用开放模式如rb打开,但它提出了一个坏模式的值错误

Traceback (most recent call last):
  File "C:\Users\Gowtham\Desktop\Quarantine python\Image manipulation\img.py", line 3, in <module>
    image1 = Image.open('img1.jpg',"rb")
  File "C:\Users\Gowtham\Anaconda3\lib\site-packages\PIL\Image.py", line 2599, in open
    raise ValueError("bad mode %r" % mode)
ValueError: bad mode 'rb'
[Finished in 1.047s]

Tags: inpyimagepilmode错误模式open
1条回答
网友
1楼 · 发布于 2024-10-03 00:16:31

根据[ReadTheDocs.Pillow]: PIL.Image.open(fp, mode='r')强调是我的):

  • mode – The mode. If given, this argument must be “r”.

可能,保留此参数只是为了向后兼容(或与其他open类似函数保持一致)

将代码(行)更改为:

image1 = Image.open("img1.jpg")

相关问题 更多 >