仅调整图片的宽度
Adjusting only the width of a picture
说一张尺寸为 (width = 200, height = 250)
的图片
我想把尺码改成(width = 400, height = 250)
怎么可能不报错"IndexError: image index out of range"?
使用PIL
:
from PIL import Image
im=Image.open(filename)
im2=im.resize((400,250))
im2.save(filename)
如果当前,保存为新图像,但如果要显示它,请执行:
im2.show()
就这么简单。
PIL.Image.resize
做到了。
相关:
See the docs
See the docs about this
注意第二个参数,它有一个默认参数(0
),它使用NearestNeighbors
,如果你将它设置为1
,它是LANCZOS
,如果你设为2
就是BILINEAR
,设为3
就是BICUBIC
所以看看你最喜欢什么:-)
试试这些代码
import cv2
img=cv2.imread("image.jpg")
resize=cv2.resizes(img,(400,250))
cv2.imshow("Image",resize)
说一张尺寸为 (width = 200, height = 250)
我想把尺码改成(width = 400, height = 250)
怎么可能不报错"IndexError: image index out of range"?
使用PIL
:
from PIL import Image
im=Image.open(filename)
im2=im.resize((400,250))
im2.save(filename)
如果当前,保存为新图像,但如果要显示它,请执行:
im2.show()
就这么简单。
PIL.Image.resize
做到了。
相关:
See the docs
See the docs about this
注意第二个参数,它有一个默认参数(0
),它使用NearestNeighbors
,如果你将它设置为1
,它是LANCZOS
,如果你设为2
就是BILINEAR
,设为3
就是BICUBIC
所以看看你最喜欢什么:-)
试试这些代码
import cv2
img=cv2.imread("image.jpg")
resize=cv2.resizes(img,(400,250))
cv2.imshow("Image",resize)