python - python中的枕头矩形不让我有足够的论据
问题描述
我已经尝试运行此代码并根据此 youtube视频制作类似骰子的图像版本, 但出现错误:
runfile('C:/Users/Sohrab/Desktop/temp.py', wdir='C:/Users/Sohrab/Desktop')
Traceback (most recent call last):
File "C:\Users\Sohrab\Desktop\temp.py", line 25, in <module>
nimd.rectangle([x, y, x+dicesize, y+dicesize],thisSectorColor, thisSectorColor)
File "C:\Users\Sohrab\anaconda3\lib\site-packages\PIL\ImageDraw.py", line 248, in rectangle
ink, fill = self._getink(outline, fill)
File "C:\Users\Sohrab\anaconda3\lib\site-packages\PIL\ImageDraw.py", line 113, in _getink
ink = self.draw.draw_ink(ink)
SystemError: new style getargs format but argument is not a tuple
这是代码:
from PIL import Image,ImageOps,ImageDraw
img = Image.open('best.jpg')
img = ImageOps.grayscale(img)
img = ImageOps.equalize(img)
dicew = 100
dicesize = int( img.width * 1.0 / dicew )
diceh = int(img.height * 1.0 / img.width * dicew)
# print(img.width,img.height, dicew, diceh, dicesize)
nim = Image.new('L', (img.width,img.height), 'white')
nimd = ImageDraw.Draw(nim)
for y in range( 0 , img.height - dicesize , dicesize ):
for x in range(0, img.width-dicesize, dicesize):
thisSectorColor = 0
for dicex in range(0,dicesize):
for dicey in range(0,dicesize):
thisColor=img.getpixel((x+dicex, y+dicey))
thisSectorColor += thisColor
thisSectorColor /= (dicesize ** 2)
nimd.rectangle([(x, y), (x+dicesize, y+dicesize)],thisSectorColor)
nim.show()
我在 Spyder 上运行了内核 3.8 的代码,并且已经安装了 Pillow 库。提前致谢。
解决方案
推荐阅读
- html - 显示:inline-flex;和 flex-wrap:wrap; 不填充上一行文本
- c++ - 如何将无序映射的值设置为 0 以外的数字
- python - 如何计算某个字符下面的行数?
- javascript - DataTable排序空列
- android - 如何将新的 conscrypt 库集成到 Android 并默认使用
- vector - 具有 O(log n) indexOf 操作的列表
- python - 为什么python窗口总是关闭以及如何停止它?
- list - 如何使用 MIT 应用程序发明者从字典中的键返回给定值?
- c# - 如何更新 DAL 中的桥接表?
- r - 获得包含线性模型的 R 函数以运行的问题