Skip to content

Allow capturing a JPEG into a bytes object #13

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 21, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions adafruit_pycamera/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,25 @@ def continuous_capture_start(self):
"""Switch the camera to continuous-capture mode"""
pass # pylint: disable=unnecessary-pass

def capture_into_jpeg(self):
"""Captures an image and returns it in JPEG format.

Returns:
bytes: The captured image in JPEG format, otherwise None if the capture failed.
"""
self.camera.reconfigure(
pixel_format=espcamera.PixelFormat.JPEG,
frame_size=self.resolution_to_frame_size[self._resolution],
)
time.sleep(0.1)
jpeg = self.camera.take(1)
if jpeg is not None:
print(f"Captured {len(jpeg)} bytes of jpeg data")
print("Resolution %d x %d" % (self.camera.width, self.camera.height))
else:
print("JPEG capture failed")
return jpeg

def capture_into_bitmap(self, bitmap):
"""Capture an image and blit it into the given bitmap"""
bitmaptools.blit(bitmap, self.continuous_capture(), 0, 0)
Expand Down