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

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

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

安裝pygame

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

python -m pip install -U pygame --user

要查看它是否有效,請(qǐng)運(yùn)行包含的示例之一:

python -m pygame.examples.aliens

如果可行,我們就可以開(kāi)始了!

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

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

使用 PyGame 顯示圖像

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

# 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)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論

桐乡市| 鸡西市| 贵南县| 榆中县| 邵武市| 镶黄旗| 新丰县| 西乌| 辰溪县| 屏东县| 厦门市| 惠东县| 汾西县| 桐乡市| 营山县| 襄城县| 峨眉山市| 神农架林区| 克山县| 博爱县| 山西省| 昌平区| 尚义县| 巴林左旗| 郴州市| 舒兰市| 丰原市| 金溪县| 鄂托克前旗| 开远市| 普安县| 内乡县| 绥棱县| 渝北区| 邹平县| 明溪县| 米林县| 霍山县| 西和县| 胶州市| 忻城县|