簡體   English   中英

如何在pygame中顯示圖像?

[英]How to display Image in pygame?

我想從網絡攝像頭加載圖像以在pygame上顯示我正在使用視頻捕捉

from VideoCapture import Device
import pygame
import time
In=1
pygame.init()
w = 640
h = 480
size=(w,h)
screen = pygame.display.set_mode(size) 

while True:
    cam = Device()
    cam.saveSnapshot(str(In)+".jpg") 
    img=pygame.image.load(In)
    screen.blit(img,(0,0))
    In=int(In)+1
    In=str(In)

為什么這不起作用.Pygame窗口打開但沒有顯示?

你必須告訴pygame 更新顯示

在將圖像blitting到屏幕后,在循環中添加以下行:

pygame.display.flip()

順便說一句,您可能希望限制每秒拍攝的圖像數量。 使用time.sleeppygame時鍾


from VideoCapture import Device
import pygame
import time
In=1
pygame.init()
w = 640
h = 480
size=(w,h)
screen = pygame.display.set_mode(size) 
c = pygame.time.Clock() # create a clock object for timing

while True:
    cam = Device()
    filename = str(In)+".jpg" # ensure filename is correct
    cam.saveSnapshot(filename) 
    img=pygame.image.load(filename) 
    screen.blit(img,(0,0))
    pygame.display.flip() # update the display
    c.tick(3) # only three images per second
    In += 1

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM