zoukankan      html  css  js  c++  java
  • python pillow 绘制图片

    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

  • 相关阅读:
    WPF数据绑定机制是如何实现
    C#自定义特性的使用
    MVVMLight学习笔记(一)---MVVMLight概述
    C# Autofac学习笔记
    EFCodeFirst快速搭建入门
    SQL having与where用法区别
    EventWaitHandle 类
    C# EF 使用 (CodeFirst模式)
    wmi 远程启动程序
    Centos 7 的一些 基础知识
  • 原文地址:https://www.cnblogs.com/sea-stream/p/11100360.html
Copyright © 2011-2022 走看看