• 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模块学习 re 正则表达式
  • python脚本实现数据导出excel格式的简单方法(推荐)
  • 在Python中使用mongoengine操作MongoDB教程
  • Python入门篇之条件、循环
  • 在Python中处理字符串之isdecimal()方法的使用
  • Python遍历目录中的所有文件的方法
  • 利用QT写一个极简单的图形化Python闹钟程序
  • Python实现发送email的几种常用方法
  • python通过smpt发送邮件的方法
  • Python 功能和特点(新手必学)

文章分类

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

最近更新的内容

    • python使用clear方法清除字典内全部数据实例
    • python获取当前用户的主目录路径方法(推荐)
    • 深入解析Python中函数的参数与作用域
    • Tornado Web服务器多进程启动的2个方法
    • Python中使用SAX解析xml实例
    • Ubuntu 14.04+Django 1.7.1+Nginx+uwsgi部署教程
    • Python深入学习之装饰器
    • python测试驱动开发实例
    • 解决uWSGI的编码问题详解
    • Python2.x中str与unicode相关问题的解决方法

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

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