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

yipeiwu_com6年前Python基础

本文实例讲述了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 /zb_users/upload/202003/i4eeohfkxw4 .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中numpy数组的合并实例讲解

基于Python中numpy数组的合并实例讲解

Python中numpy数组的合并有很多方法,如 - np.append() - np.concatenate() - np.stack() - np.hstack() - np...

python实现最大优先队列

本文实例为大家分享了python实现最大优先队列的具体代码,供大家参考,具体内容如下 说明:为了增强可复用性,设计了两个类,Heap类和PriorityQ类,其中PriorityQ类继承...

Python中修改字符串的四种方法

在Python中,字符串是不可变类型,即无法直接修改字符串的某一位字符。  因此改变一个字符串的元素需要新建一个新的字符串。 常见的修改方法有以下4种。 方法1:将字符串转...

pandas 取出表中一列数据所有的值并转换为array类型的方法

pandas 取出表中一列数据所有的值并转换为array类型的方法

如下所示: # -*-coding: utf-8 -*- import pandas as pd #读取csv文件 df=pd.read_csv('A_2+20+DoW+VC.csv...

python 解决cv2绘制中文乱码问题

python 解决cv2绘制中文乱码问题

因为使用cv2.putText() 只能显示英文字符,中文会出现乱码问题, 因此使用PIL在图片上绘制添加中文,可以指定字体文件。 大体思路: OpenCV图片格式转换成PIL的图片格式...