python - 如何在python中生成每个像素都是随机颜色的图像
问题描述
我正在尝试为每个像素制作具有随机颜色的图像,然后打开一个窗口来查看图像。
import PIL, random
import matplotlib.pyplot as plt
import os.path
import PIL.ImageDraw
from PIL import Image, ImageDraw, ImageFilter
im = Image.new("RGB", (300,300))
for r in range(0,300):
for c in range(0,300):
re = random.randint(0, 255)
gr = random.randint(0, 255)
bl = random.randint(0, 255)
im[r][c]=[re,gr,bl]
im.show()
14 bl = random.randint(0, 255)
---> 15 im[r][c]=[re,gr,bl]
16 im.show()
TypeError: 'Image' object does not support indexing
解决方案
推荐阅读
- html - CSS grid-template-areas 占用空间,即使列和行是空白的
- swift - 快速字符串任务
- c# - CS1061:“IEnumerable
" 不包含 'OrderByDescending()' 的定义 - json - JQ如何通过转义从内部数组中读取数据
- amazon-web-services - 在 AWS-ec2 上安装 Beats 以发送到本地 ELK
- swiftui - 如何在 SwiftUI 中的 WatchOS 导航栏下显示具有 primaryAction 位置的 ToolbarItem
- r - 在 R 中导入 csv 时分离样本
- pyspark - 如何使用 pyspark 设置动态 where 子句
- apache-spark - PySpark - 增加价值交叉的排名
- php - Select2 从数据库中获取已经输入的信息并进行编辑