#22 Use BytesIO for camera capture
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
from picam import PiCam
|
from src.picam import PiCam
|
||||||
|
|
||||||
|
from io import BytesIO
|
||||||
from picamera import PiCamera
|
from picamera import PiCamera
|
||||||
|
|
||||||
class PiCam1(PiCam):
|
class PiCam1(PiCam):
|
||||||
@@ -36,12 +37,17 @@ class PiCam1(PiCam):
|
|||||||
def capture(self, preview: bool = False) -> bytes:
|
def capture(self, preview: bool = False) -> bytes:
|
||||||
# Bytes to hold output buffer
|
# Bytes to hold output buffer
|
||||||
out = bytes()
|
out = bytes()
|
||||||
|
bytes_stream = BytesIO()
|
||||||
|
|
||||||
if not preview:
|
if not preview:
|
||||||
# If preview we'll already have the right resolution
|
# If preview we'll already have the right resolution
|
||||||
self.set_camera_resolution(self.capture_resolution)
|
self.set_camera_resolution(self.capture_resolution)
|
||||||
|
|
||||||
self.camera.capture(out, format='rgb', use_video_port=preview)
|
self.camera.capture(bytes_stream, format='rgb', use_video_port=preview)
|
||||||
|
|
||||||
|
bytes_stream.seek(0)
|
||||||
|
bytes_stream.readinto(out)
|
||||||
|
bytes_stream.close()
|
||||||
|
|
||||||
if not preview:
|
if not preview:
|
||||||
# If preview we'll already have the right resolution
|
# If preview we'll already have the right resolution
|
||||||
|
|||||||
Reference in New Issue
Block a user