python画的图怎么保存_python通过PyGame绘制图像并保存为图片文件的代码
把开发过程中常用的一些内容片段记录起来,下边内容是关于python通过PyGame绘制图像并保存为图片文件的内容,希望对大伙有较大好处。
''' pg_draw_circle_save101.py
draw a blue solid circle on a white background
save the drawing to an image file
tested with Python 2.7 and PyGame 1.9.2 by vegaseat 16may2013
'''
import pygame as pg
# pygame uses (r, g, b) color tuples
white = (255, 255, 255)
blue = (0, 0, 255)
width = 300
height = 300
# create the display window
win = pg.display.set_mode((width, height))
# optional title bar caption
pg.display.set_caption("Pygame draw circle and save")
# default background is black, so make it white
win.fill(white)
# draw a blue circle
# center coordinates (x, y)
radius = min(center)
# width of 0 (default) fills the circle
# otherwise it is thickness of outline
width = 0
# draw.circle(color, pos, radius, width)
pg.draw.circle(win, blue, center, radius, width)
# now save the drawing
# can save as .bmp .tga .png or .jpg
fname = "circle_blue.png"
pg.image.save(win, fname)
print("file {} has been saved".format(fname))
# update the display window to show the drawing
pg.display.flip()
# event loop and exit conditions
# (press escape key or click window title bar x to exit)
while True:
for event in pg.event.get():
if event.type == pg.QUIT:
# most reliable exit on x click
pg.quit()
raise SystemExit
elif event.type == pg.KEYDOWN:
# optional exit with escape key
if event.key == pg.K_ESCAPE:
pg.quit()
raise SystemExit
python画的图怎么保存_python通过PyGame绘制图像并保存为图片文件的代码相关推荐
- python画双折线图详解_Python教程:matplotlib 绘制双Y轴曲线图
#-*- coding: utf-8 -*- #调用包 importpandas as pdimportnumpy as npimportmatplotlib.pyplot as plt#读取文件 i ...
- python画一棵树源代码_Python+Turtle动态绘制一棵树实例分享
本文实例主要是对turtle的使用,实现Python+turtle动态绘制一棵树的实例,具体代码: # drawtree.py from turtle import Turtle, mainloop ...
- python画完图 程序暂停运行_Python编程:认识IDLE,编写保存运行第1个程序
Python编程需要有一个合适的编辑器. 就像我们平常写文章用Word,处理数据用Excel一样,处理图片要用PS或美图秀秀,我们编写Python程序也需要一个编辑器,正所谓工欲善其事,必先利其器. ...
- python画螺旋状图形教程_Python实现的绘制三维双螺旋线图形功能示例
本文实例讲述了Python实现的绘制三维双螺旋线图形功能.分享给大家供大家参考,具体如下: 代码: # -*- coding:utf-8 -*- #! python3 #绘制三维双螺旋线 import ...
- 通过python画矢量图(matplotlib,有代码)
python画矢量图(有代码) python的matplotlib可以保存的文件格式 word可以插入哪些图片格式呢 代码 中文乱码问题 有些同学因为文章的要求,图片插入到word里的时候需要足够清晰 ...
- python 画三维函数图-Python画三维图-----插值平滑数据
一.二维的插值方法: 原始数据(x,y) 先对横坐标x进行扩充数据量,采用linspace.[如下面例子,由7个值扩充到300个] 采用scipy.interpolate中的spline来对纵坐标数据 ...
- python画折线图代码-python画折线示意图实例代码
python画折线图方法 前做PPT要用到折线图,嫌弃EXCEL自带的看上去不好看,就用python写了一个画折线图的程序. import matplotlib.pyplot as plt x=[1, ...
- python画折线图详解-python如何画折线图
python画折线图利用的是matplotlib.pyplot.plot的工具来绘制折线图,这里先给出一个段代码和结果图:# -*- coding: UTF-8 -*- import numpy as ...
- python画折线图详解-利用python画出折线图
本文实例为大家分享了python画折线图的具体代码,供大家参考,具体内容如下 # encoding=utf-8 import matplotlib.pyplot as plt from pylab i ...
最新文章
- qt 显示加速_新能源 | 吉利星越ePro上市 补贴后17.58万起售 加速更快油耗更低
- 二叉树的建造、递归与非递归遍历
- Redis持久化实践及数据恢复
- QT的QQmlProperty类的使用
- Mysql 常用函数(19)- mod 函数
- 移植tslib(s3c2440)
- 使用DbContextPool提高EfCore查询性能
- 测绘地理信息标准(国家、行业、地方)大全来了:测绘地理信息标准化服务平台
- 收藏 | 深度学习框架简史:TensorFlow和PyTorch双头垄断
- (22)FPGA比较器设计(第5天)
- OpenGL学习笔记(13)位图与文字
- oracle with as用法_关于Oracle with语句用法说明
- 在线卡密销售系统之JAVA WEB学习之路
- 信息学奥赛一本通C++语言——1129:统计数字字符个数
- 开发者必看的免费资源分享网站,让开发更简单!
- android分析声音中的节奏,[AndroidTips]调用TextToSpeech朗读的时候怎么中间停顿
- 龙芯CPU处理器和芯片资料介绍
- 指纹存取控制系统的全球与中国市场2022-2028年:技术、参与者、趋势、市场规模及占有率研究报告
- LabVIEW笔记(一)
- RBF神经网络基本思想