码迷,mamicode.com
首页 > 编程语言 > 详细

python 根据数组生成图片

时间:2019-06-28 01:00:47      阅读:216      评论:0      收藏:0      [点我收藏+]

标签:生成   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(x<0):
                pixTuple = (105,105,105,x)
                img.putpixel((i,j),pixTuple)
            elif(x<25):
                pixTuple = (255,255,255,x)
                img.putpixel((i,j),pixTuple)
            elif(x<65):
                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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!