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

python pillow 绘制图片

时间:2019-06-28 00:48:55      阅读:95      评论:0      收藏:0      [点我收藏+]

标签:import   cost   eval   app   append   print   bin   col   style   

 

demo1

#coding=utf-8
from PIL import Image
img = Image.new("RGB",(5,5))###创建一个5*5的图片
pixTuple = (255,0,255,15)###三个参数依次为R,G,B,A   R:红 G:绿 B:蓝 A:透明度
for i in range(5):
    for j in range(5):
        img.putpixel((i,j),pixTuple)
img.save("bb.png")

 

demo2

import time
from PIL import Image
with open("aa-1.log","r") as f:
    costlist=eval(f.read())
img = Image.new("RGB",(792,675))###创建图片
single=[]
count=0
for i in range(600):
    for j in range(600):
        x=int(costlist[count])
        #if(x not in single):
            #single.append(x)
        if(x<10):
            pixTuple = (255,182,193,x)
            img.putpixel((i,j),pixTuple)
        elif(x<20):
            pixTuple = (255,20,147,x)
            img.putpixel((i,j),pixTuple)
        elif(x<30):
            pixTuple = (30,144,255,x)
            img.putpixel((i,j),pixTuple)
        elif(x<40):
            pixTuple = (135,206,235,x)
            img.putpixel((i,j),pixTuple)
        elif(x<50):
            pixTuple = (30,144,255,x)
            img.putpixel((i,j),pixTuple)
        elif(x<60):
            pixTuple = (127,255,170,x)
            img.putpixel((i,j),pixTuple)
        elif(x<70):
            pixTuple = (144,238,144,x)
            img.putpixel((i,j),pixTuple)
        elif(x<80):
            pixTuple = (255,255,0,x)
            img.putpixel((i,j),pixTuple)
        elif(x<90):
            pixTuple = (255,215,0,x)
            img.putpixel((i,j),pixTuple)
        elif(x<=100):
            pixTuple = (250,128,114,x)
            img.putpixel((i,j),pixTuple)
        count+=1
img.save("bb.png")
#print(single)

 


参考:
https://blog.csdn.net/caobin0825/article/details/80338438

 

 

python pillow 绘制图片

标签:import   cost   eval   app   append   print   bin   col   style   

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

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