带有imageext的pygame导入错误

时间:2013-12-11 14:39:00

标签: python pygame

我制作了一个使用pygame打开网络摄像头的程序。我试图通过使用pygame.save(img,'image.jpg')捕获图像并将其保存到我当前的目录。

import pygame.camera
import pygame.image
import sys

pygame.camera.init()

cameras = pygame.camera.list_cameras()

print "Using camera %s ..." % cameras[0]

webcam = pygame.camera.Camera(cameras[0])

webcam.start()

# grab first frame
img = webcam.get_image()

WIDTH = img.get_width()
HEIGHT = img.get_height()

screen = pygame.display.set_mode( ( WIDTH, HEIGHT ) )
pygame.display.set_caption("pyGame Camera View")

while True :
    for e in pygame.event.get() :
        if e.type == pygame.QUIT :
            pygame.image.save(img, 'image.jpg')
        sys.exit()



    # draw frame
    screen.blit(img, (0,0))
    pygame.display.flip()
    # grab next frame    
    img = webcam.get_image()

但是这个程序出错了:

Using camera /dev/video0 ...
Traceback (most recent call last):
  File "cam1.py", line 27, in <module>
    pygame.image.save(img, 'image.jpg')
ImportError: No module named imageext

代码有什么问题?请帮我 !有没有其他方法来保存图像?

1 个答案:

答案 0 :(得分:0)

当我将扩展名更改为.bmp时,代码工作正常!默认情况下,pygame仅支持未压缩的BMP图像

我没有PyGame的全图像支持,这就是为什么我被迫坚持使用BMP格式的图像

获取更多信息here(Pygame官方文档)