How to save captured image to disk, using Pygame

前端 未结 1 1583
眼角桃花
眼角桃花 2021-02-14 08:02

This is my code, which starts the webcam :

import pygame.camera
import pygame.image
import sys

pygame.camera.init()

cameras = pygame.camera.list_cameras()

pri         


        
相关标签:
1条回答
  • 2021-02-14 08:46

    When you call webcam.get_image it returns an RGB Surface. So just call pygame.image.save(), the file type is determined by the extension and defaults to TGA. Options are BMP, TGA, PNG, and JPEG. In this case you could append this line to your file.

    pygame.image.save(img, "image.jpg")
    

    Check out http://www.pygame.org/docs/ref/image.html and http://www.pygame.org/docs/ref/camera.html

    0 讨论(0)
提交回复
热议问题