#22 Fix bytearray errors
This commit is contained in:
@@ -17,14 +17,14 @@ class PiCam:
|
|||||||
"""
|
"""
|
||||||
self.preview_resolution = resolution
|
self.preview_resolution = resolution
|
||||||
|
|
||||||
def capture(self) -> bytes:
|
def capture(self) -> bytearray:
|
||||||
"""Capture an image
|
"""Capture an image
|
||||||
|
|
||||||
:returns: Image data as a byte buffer
|
:returns: Image data as a byte buffer
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
def capture_preview(self) -> bytes:
|
def capture_preview(self) -> bytearray:
|
||||||
"""Capture a preview image for the viewfinder
|
"""Capture a preview image for the viewfinder
|
||||||
|
|
||||||
:returns: Image data as a byte buffer
|
:returns: Image data as a byte buffer
|
||||||
|
|||||||
@@ -36,13 +36,17 @@ class PiCam1(PiCam):
|
|||||||
|
|
||||||
def capture(self, preview: bool = False) -> bytearray:
|
def capture(self, preview: bool = False) -> bytearray:
|
||||||
# Bytes to hold output buffer
|
# Bytes to hold output buffer
|
||||||
out = bytearray()
|
if preview:
|
||||||
bytes_stream = BytesIO()
|
# Multiply by 3 for individual R, G, B values
|
||||||
|
out = bytearray((self.preview_resolution[0] * self.preview_resolution[1]) * 3)
|
||||||
|
else:
|
||||||
|
out = bytearray((self.capture_resolution[0] * self.capture_resolution[1]) * 3)
|
||||||
|
|
||||||
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)
|
||||||
|
|
||||||
|
bytes_stream = BytesIO()
|
||||||
self.camera.capture(bytes_stream, format='rgb', use_video_port=preview)
|
self.camera.capture(bytes_stream, format='rgb', use_video_port=preview)
|
||||||
|
|
||||||
bytes_stream.seek(0)
|
bytes_stream.seek(0)
|
||||||
@@ -55,5 +59,5 @@ class PiCam1(PiCam):
|
|||||||
|
|
||||||
return out
|
return out
|
||||||
|
|
||||||
def capture_preview(self) -> bytes:
|
def capture_preview(self) -> bytearray:
|
||||||
return self.capture(preview=True)
|
return self.capture(preview=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user