本文实例讲述了python使用PyGame绘制图像并保存为图片文件的方法。分享给大家供大家参考。具体实现方法如下:

''' pg_draw_circle_save101.py

draw a blue solid circle on a white background

save the drawing to an image file

for result see http://prntscr.com/156wxi

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)

center = (width//2, height//2)

radius = min(center)

# width of 0 (default) fills the circle

# otherwise it is thickness of outline

width = 0

# draw.circle(Surface, 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中pygame放入图_python使用PyGame绘制图像并保存为图片文件的方法相关推荐

  1. python画的图怎么保存_python通过PyGame绘制图像并保存为图片文件的代码

    把开发过程中常用的一些内容片段记录起来,下边内容是关于python通过PyGame绘制图像并保存为图片文件的内容,希望对大伙有较大好处. ''' pg_draw_circle_save101.py d ...

  2. 如何用python画出一般函数图_python如何画函数图像

    通过图像可以直观地学习函数变化.分布等规律,在学习函数.概率分布等方面效果显著.下面我们尝试用Python的2D绘图库matplotlib来绘制函数图像. 下面我们来实现一个简单的函数: 首先,调用m ...

  3. python中turtle要安装吗_Python之pygame安装过程中出现的问题以及解决方法

    Hi,大家好,我是Wlong,第二篇文章呢,打算聊一聊前段时间安装Pygame遇到的一些问题以及解决方法.第一篇文章提到了我正在看<Python编程 从入门到实践>这本书,大概在上周左右, ...

  4. python中seaborn画swarm图_Python可视化 | Seaborn5分钟入门(四)——stripplot和swarmplot

    微信公众号:「Python读财」 如有问题或建议,请公众号留言 Seaborn是基于matplotlib的Python可视化库. 它提供了一个高级界面来绘制有吸引力的统计图形.Seaborn其实是在m ...

  5. python创建数组放入矩阵_python数组和矩阵使用总结

    1.数组和矩阵常见用法 Python使用NumPy包完成了对N-维数组的快速便捷操作.使用这个包,需要导入numpy. SciPy包以NumPy包为基础,大大的扩展了numpy的能力.因此只要导入了s ...

  6. python创建数组放入矩阵_python创建数组并存入数据库

    {"moduleinfo":{"card_count":[{"count_phone":1,"count":1}],&q ...

  7. python爬今日头条组图_python 爬虫抓取今日头条街拍图片

    1. 打开google浏览器,输入www.toutiao.com, 搜索街拍.html 2.打开开发者选项,network监看加载的xhr, 数据是ajax异步加载的,能够看到preview里面的da ...

  8. python用matplotlib画雷达图_python使用matplotlib绘制雷达图

    本文实例为大家分享了python使用matplotlib绘制雷达图的具体代码,供大家参考,具体内容如下 示例代码: # encoding: utf-8 import pandas as pd impo ...

  9. python中画圆的代码_Python使用matplotlib绘制圆形代码实例

    1.定义一个画圆的函数import numpy as np import matplotlib.pyplot as plt def plot_circle(center=(3, 3),r=2): x ...

  10. python画图程序没有图_解决python中使用plot画图,图不显示的问题

    解决python中使用plot画图,图不显示的问题 对以下数据画图结果图不显示,修改过程如下 df3 = {'chinese':109, 'American':88, 'German': 66, 'K ...

最新文章

  1. Struts2 @ResultPath注释示例
  2. UVA 10746 Crime Wave - The Sequel
  3. python urllib.request 爬虫 数据处理-python爬虫之json数据处理
  4. rhel6.2 yum
  5. The Illustrated Transformer 翻译
  6. html表单验证js代码,JavaScript表单验证实现代码
  7. python yield使用
  8. 用DirectX Audio和DirectShow播放声音和音乐(4)
  9. 韩顺平 servlet 笔记 第4讲
  10. sql power bi_在SQL,Power BI和MS Excel中计算移动平均值
  11. android toast_Android Toast
  12. Flutter 深度学习 — Cookbook(Flutter菜谱)
  13. SharePoint2010探索日志
  14. WinHex中文版下载 v16.9 汉化破解版
  15. LGTM,XGBOOST,LIGHTGBM
  16. html隐藏域倒计时,一个网页倒计时的实现
  17. Java实现批量下载《神秘的程序员》漫画
  18. 一台微型计算机的好坏 主要取决于,计算机一级MSOffice应用选择题
  19. Xv6 I/O 与文件描述符
  20. Android OpenGL ES 画球体

热门文章

  1. 小D课堂 - 零基础入门SpringBoot2.X到实战_第8节 数据库操作之整合Mybaties和事务讲解_36、SpringBoot整合mybatis之事务处理实战...
  2. 阶段1 语言基础+高级_1-3-Java语言高级_08-JDK8新特性_第2节 Stream流式思想概述_2_使用Stream流的方式,遍历集合...
  3. Rabbitmq消息队列(二) Hello World! 模拟简单发送接收
  4. OJ-1:时钟问题【九度1553】
  5. PE框架学习之道:PE框架——style的配置
  6. spring3.1.0 jar包详解说明
  7. MariaDB修改端口号
  8. CST,CET,UTC,GMT,DST,Unix时间戳几种常见时间概述与关系(转)
  9. SpringMVC+Spring+Mybatis简单总结
  10. [HAOI2006] 聪明的猴子