python 使用PIL 写入像素点画图片

原文件如图所示 

很像RGB的格式 ,写脚本

#!/usr/bin/python
# -*- coding:utf8 -
from PIL import Image
x = 50    #x坐标  通过对txt里的行数进行整数分解
y = 2700  #y坐标  x*y=行数 13500行,150和900也可以

im = Image.new("RGB", (x, y))
file = open('basic.txt')

for i in range(0, x):
    for j in range(0, y):
        line = file.readline().replace('(','').replace(')','')  #获取一行rgb值,并且把()都替换为空
        rgb = line.split(",") #逗号分割
        im.putpixel((i, j), (int(rgb[0]), int(rgb[1]), int(rgb[2]))) #(i,j)为坐标,后面的是像素点

im.save("flag.png")

在画图中调整方向即可

猜你喜欢

转载自blog.csdn.net/qq_40657585/article/details/84858709