From ff072b5c21091405084042be11e5c57bb80b9331 Mon Sep 17 00:00:00 2001
From: FurWaz <fur.waz06@gmail.com>
Date: Fri, 25 Nov 2022 14:26:58 +0100
Subject: [PATCH] Added image cache for smoother experience

---
 .../src/main/java/Structures/PhotoInfo.java   | 20 +++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)

diff --git a/Sources/app/src/main/java/Structures/PhotoInfo.java b/Sources/app/src/main/java/Structures/PhotoInfo.java
index 7dc3d0d..5cdd815 100644
--- a/Sources/app/src/main/java/Structures/PhotoInfo.java
+++ b/Sources/app/src/main/java/Structures/PhotoInfo.java
@@ -13,6 +13,14 @@ public class PhotoInfo implements Serializable {
     byte[] image = null;
     ZoneInfo zone = null;
     List<PathView> pathViews = new ArrayList<>();
+    transient Bitmap bitmap = null;
+
+    protected void createBitmap() {
+        Bitmap source = BitmapFactory.decodeByteArray(this.image, 0, this.image.length);
+        Matrix mat = new Matrix();
+        mat.postRotate(90);
+        this.bitmap = Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), mat, true);
+    }
 
     public PhotoInfo() {
 
@@ -24,11 +32,14 @@ public class PhotoInfo implements Serializable {
 
     public PhotoInfo(byte[] im) {
         this.image = im;
+        createBitmap();
+        this.askForSave();
     }
 
     public PhotoInfo(byte[] im, Orientation orientation) {
         this.image = im;
         this.orientation = orientation;
+        createBitmap();
         this.askForSave();
     }
 
@@ -48,14 +59,15 @@ public class PhotoInfo implements Serializable {
     public Bitmap getBitmap() {
         if (this.image == null || this.image.length == 0)
             return null;
-        Bitmap source = BitmapFactory.decodeByteArray(this.image, 0, this.image.length);
-        Matrix mat = new Matrix();
-        mat.postRotate(90);
-        return Bitmap.createBitmap(source, 0, 0, source.getWidth(), source.getHeight(), mat, true);
+        if (this.bitmap != null) return this.bitmap;
+
+        createBitmap();
+        return this.bitmap;
     }
 
     public void setImage(byte[] data) {
         this.image = data;
+        createBitmap();
         this.askForSave();
     }
 
-- 
GitLab