Skip to content

Commit 460b169

Browse files
authored
Merge pull request adafruit#13 from brentru/allow-jpg-save
Allow capturing a JPEG into a bytes object
2 parents fa65735 + 60a6326 commit 460b169

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

adafruit_pycamera/__init__.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -703,6 +703,25 @@ def continuous_capture_start(self):
703703
"""Switch the camera to continuous-capture mode"""
704704
pass # pylint: disable=unnecessary-pass
705705

706+
def capture_into_jpeg(self):
707+
"""Captures an image and returns it in JPEG format.
708+
709+
Returns:
710+
bytes: The captured image in JPEG format, otherwise None if the capture failed.
711+
"""
712+
self.camera.reconfigure(
713+
pixel_format=espcamera.PixelFormat.JPEG,
714+
frame_size=self.resolution_to_frame_size[self._resolution],
715+
)
716+
time.sleep(0.1)
717+
jpeg = self.camera.take(1)
718+
if jpeg is not None:
719+
print(f"Captured {len(jpeg)} bytes of jpeg data")
720+
print("Resolution %d x %d" % (self.camera.width, self.camera.height))
721+
else:
722+
print("JPEG capture failed")
723+
return jpeg
724+
706725
def capture_into_bitmap(self, bitmap):
707726
"""Capture an image and blit it into the given bitmap"""
708727
bitmaptools.blit(bitmap, self.continuous_capture(), 0, 0)

0 commit comments

Comments
 (0)