python 根据数组生成图片

2020-12-13 03:59

阅读:262

标签:生成   inf   put   col   pen   lis   open   eva   cep   

 

aa-1.log
链接:https://pan.baidu.com/s/1bEbXeJtRF792DX0x8TGwhA  密码:zwky

#coding=utf-8

import time
from PIL import Image
with open("aa-1.log","r") as f:
    costlist=eval(f.read())
img = Image.new("RGB",(675,792))###创建图片
print(len(costlist))

single=[]
count=0

output=[]
for i in range(675):
    y=[]
    for j in range(792):
        try:
            if(costlist[count]=="[" or costlist[count]=="]"):
                print(costlist[count])
            x=int(costlist[count])
            #if(x not in single):
                #single.append(x)
            if(x0):
                pixTuple = (105,105,105,x)
                img.putpixel((i,j),pixTuple)
            elif(x25):
                pixTuple = (255,255,255,x)
                img.putpixel((i,j),pixTuple)
            elif(x65):
                pixTuple = (211,211,211,x)
                img.putpixel((i,j),pixTuple)
            else:
                pixTuple = (0,0,0,x)
                img.putpixel((i,j),pixTuple)
            count+=1
            y.append(x)
        except Exception as e:
            print(e,i,j)
    output.append(y)


with open("aa.log","w") as f:
    f.write(str(output).replace("[","{").replace("]","}"))

pixTuple = (255,0,0,0)
img.putpixel((337,300),pixTuple)
img.save("bb.png")
#print(single)

 

效果图

技术图片

 

 

 

 

python 根据数组生成图片

标签:生成   inf   put   col   pen   lis   open   eva   cep   

原文地址:https://www.cnblogs.com/sea-stream/p/11100402.html

上一篇:DAY03 WINDOWS 实验报告

下一篇:进程线程


评论


亲,登录后才可以留言!