首页 > 编程语言 > 详细

python pillow 绘制图片

时间:2019-06-28 00:40:20      阅读:109      评论:0      收藏:0      [点我收藏+]

 

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 绘制图片

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!