最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

使用PyGame顯示圖像的四種方案實例代碼

 更新時間:2022年12月27日 16:28:02   作者:堅果的博客  
由于前面學(xué)習(xí)了使用pygame的簡單操作,現(xiàn)在學(xué)習(xí)當(dāng)前的pygame怎么加載圖片,下面這篇文章主要給大家介紹了關(guān)于使用PyGame顯示圖像的四種方案,文中通過圖文介紹的非常詳細,需要的朋友可以參考下

安裝pygame

安裝 pygame 的最佳方法是使用 pip 工具(python 使用它來安裝包)。請注意,在最新版本中,這與 python 一起提供。我們使用 –user 標(biāo)志告訴它安裝到主目錄,而不是全局。

python -m pip install -U pygame --user

要查看它是否有效,請運行包含的示例之一:

python -m pygame.examples.aliens

如果可行,我們就可以開始了!

在pygame窗口上顯示圖像有四個基本步驟:

  • 使用pygame 的display.set_mode()方法創(chuàng)建一個顯示表面對象。
  • 使用 pygame 的 image.load() 方法創(chuàng)建一個 Image 表面對象,即在其上繪制圖像的表面對象。
  • 使用pygame顯示表面對象的blit()方法將圖像表面對象復(fù)制到顯示表面對象。
  • 使用 pygame 的display.update()方法在 pygame 窗口上顯示顯示表面對象。

使用 PyGame 顯示圖像

在這里,我們首先導(dǎo)入所需的庫,然后設(shè)置圖像的寬度和高度,然后創(chuàng)建該尺寸的顯示表面,然后在 image.load() 函數(shù)中給出所需圖像的路徑,最后遍歷列表事件對象。

# importing required library
import pygame

# activate the pygame library .
pygame.init()
X = 800
Y = 800

# create the display surface object
# of specific dimension..e(X, Y).
scrn = pygame.display.set_mode((X, Y))

# set the pygame window name
pygame.display.set_caption('image')

# create a surface object, image is drawn on it.
imp = pygame.image.load("avatar.jpeg").convert()

# Using blit to copy content from one surface to other
scrn.blit(imp, (0, 0))

# paint screen one time
pygame.display.flip()
status = True
while (status):

# iterate over the list of Event objects
# that was returned by pygame.event.get() method.
	for i in pygame.event.get():

		# if event object type is QUIT
		# then quitting the pygame
		# and program both.
		if i.type == pygame.QUIT:
			status = False

# deactivates the pygame library
pygame.quit()

總結(jié)

到此這篇關(guān)于使用PyGame顯示圖像的四種方案的文章就介紹到這了,更多相關(guān)PyGame顯示圖像內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論

台州市| 赫章县| 高唐县| 忻州市| 河北区| 东海县| 瑞金市| 益阳市| 腾冲县| 绿春县| 宁河县| 赤城县| 浮山县| 白城市| 洛宁县| 嘉禾县| 汶上县| 新和县| 区。| 克什克腾旗| 河间市| 内黄县| 绍兴县| 榆树市| 灵丘县| 玉门市| 疏勒县| 怀化市| 乌审旗| 庆城县| 宜城市| 鄂伦春自治旗| 如东县| 体育| 手游| 潼南县| 合肥市| 台湾省| 六枝特区| 绥德县| 枣庄市|