【发布时间】:2020-09-14 19:43:16
【问题描述】:
我必须使用枕头在 python 中创建调整大小算法。有些var是法语的。在这里,我在一段时间结束时添加到 i (所以 i 始终是 int)并且 x 始终是 int,因为它在范围之外。 a[x] 是一个元组。
from PIL import Image
photo=Image.open("meh.jpg")
from random import randint
taille=photo.size
largeur=int(taille[0]*facteur)
hauteur=int(taille[1]*facteur)
diffhauteur=hauteur-taille[1]
difflargeur=largeur-taille[0]
newImage= Image.new('RGB', (largeur,hauteur))
if diffhauteur>1:
i=0
while i !=taille[0]:
a=[]
for b in range(taille[1]):
liste.append(photo.getpixel((i,b))) #get all the data of the pixels in the row
for b in range(diffhauteur): #add some pixel (gradient) to get the lenght of the new img
index=randint(0,len(a)-2)
pixel2=a[index+1]
pixel1=a[index]
ab= degrade(pixel1,pixel2) #create a gradient of two pixels as a tuple
a.insert(index,ab)
for x in range (hauteur):#add the row to the new img
newImage.putpixel((i,x),a[x])
i=i+1
newImage.show()
但是,我得到了这个错误:
#here are the values
a[x]=(0.0, 0.0, -1.0)
i=0
x=6
line 71, in resizing
newImage.putpixel((i,x),a[x])
TypeError: integer argument expected, got float
对于特定值不会发生这种情况。这完全是随机的
有人有答案吗?因为它看起来很棘手或太容易了 我明天要问我的老师,但我不知道我是否能够解决这个问题。 谢谢你
【问题讨论】:
-
a[x]的值是多少?这可能是一个浮动? -
请尝试提供minimal reproducible example。我们需要猜测,否则。
-
我编辑了帖子以保留最重要的部分。对不起,我是初学者
-
抱歉,我的重点是可重现。减少代码大小很好(并且会增加获得帮助的机会),但删除运行所需的代码太多了。请尝试创建一些可以运行并导致所描述错误的代码。
-
int没有小数位。a[x]中的值有。因此,它们不是ints
标签: python python-3.x integer python-imaging-library