Selaa lähdekoodia

save screenshots as jpeg

Richard Köhl 1 vuosi sitten
vanhempi
commit
96d32f38db
1 muutettua tiedostoa jossa 8 lisäystä ja 4 poistoa
  1. 8 4
      screenshot.py

+ 8 - 4
screenshot.py

@@ -2,9 +2,11 @@ import cv2
 import time
 import datetime
 import numpy as np
+import io
 from PIL import Image
 from io import BytesIO
 from ppadb.client import Client as AdbClient
+from PIL import Image
 
 client = AdbClient(host="127.0.0.1", port=5037)
 device = client.device("192.168.178.32:5555")
@@ -95,11 +97,13 @@ def save_screenshot():
   result = device.screencap()
 
   timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
-  filename = f"fights/{timestamp}.png"
+  image = Image.open(io.BytesIO(result))
+  # TODO: write screenshots to network folder /mnt/t/nextcloud/InstantUpload/Herowars/
+  jpeg_filename = f"fights/{timestamp}.jpg"
 
-  # Save the screenshot to a file
-  with open(filename, "wb") as fp:
-    fp.write(result)
+  image = image.convert('RGB')  # Convert to RGB mode for JPEG
+  with open(jpeg_filename, "wb") as fp:
+    image.save(fp, format='JPEG', quality=85)  # Adjust quality as needed
 
   time.sleep(0.5)