• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell
您的位置:首页 > 脚本语言 >python > python使用PyGame绘制图像并保存为图片文件的方法

python使用PyGame绘制图像并保存为图片文件的方法

作者: 字体:[增加 减小] 来源:互联网

通过本文主要向大家介绍了python安装pygame,python pygame,python3.5 pygame,python3 pygame,python3.4 pygame等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

本文实例讲述了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
</div>

希望本文所述对大家的Python程序设计有所帮助。

</div>

您可能想查找下面的文章:

  • Python使用pygame模块编写俄罗斯方块游戏的代码实例
  • Python使用pygame模块编写俄罗斯方块游戏的代码实例
  • 用Python写飞机大战游戏之pygame入门(4):获取鼠标的位置及运动
  • python使用PyGame模块播放声音的方法
  • Python加pyGame实现的简单拼图游戏实例
  • python使用PyGame播放Midi和Mp3文件的方法
  • python使用PyGame绘制图像并保存为图片文件的方法
  • python使用PyGame播放Midi和Mp3文件的方法
  • python使用PyGame绘制图像并保存为图片文件的方法
  • python中pygame模块用法实例

相关文章

  • Python计算已经过去多少个周末的方法
  • Python求解平方根的方法
  • Python中的jquery PyQuery库使用小结
  • 在Linux系统上通过uWSGI配置Nginx+Python环境的教程
  • Python MySQLdb模块连接操作mysql数据库实例
  • 利用Python爬取可用的代理IP
  • Python创建模块及模块导入的方法
  • python计数排序和基数排序算法实例
  • 栈和队列数据结构的基本概念及其相关的Python实现
  • 全面了解Python的getattr(),setattr(),delattr(),hasattr()

文章分类

  • vbs
  • DOS/BAT
  • hta/htc
  • python
  • perl
  • VBA
  • ColdFusion
  • ruby
  • PowerShell
  • Lua
  • Golang
  • linux shell

最近更新的内容

    • Python和JavaScript间代码转换的4个工具
    • Python实现提取谷歌音乐搜索结果的方法
    • python实现实时监控文件的方法
    • Python使用minidom读写xml的方法
    • 全面了解Python环境配置及项目建立
    • python定时执行指定函数的方法
    • Python实现向QQ群成员自动发邮件的方法
    • Python抓取Discuz!用户名脚本代码
    • python多线程操作实例
    • python实用代码片段收集贴

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有