OSDN Git Service

Theta用にOpenGLのビューを用意する(準備)。
[gokigen/A01c.git] / wear / src / main / java / jp / sfjp / gokigen / a01c / liveview / CameraLiveViewListenerImpl.java
index b2e2b7e..79c488b 100644 (file)
@@ -1,23 +1,28 @@
 package jp.sfjp.gokigen.a01c.liveview;
 
+import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
 import android.util.Log;
 
 import androidx.annotation.NonNull;
+import androidx.annotation.Nullable;
 
 import java.util.Map;
 
 import jp.co.olympus.camerakit.OLYCamera;
 import jp.co.olympus.camerakit.OLYCameraLiveViewListener;
+import jp.sfjp.gokigen.a01c.liveview.glview.IImageProvider;
 
 /**
  *  OLYCameraLiveViewListener の実装
  *  (LiveViewFragment用)
  *
  */
-public class CameraLiveViewListenerImpl implements OLYCameraLiveViewListener, IImageDataReceiver
+public class CameraLiveViewListenerImpl implements OLYCameraLiveViewListener, IImageDataReceiver, IImageProvider
 {
     private final String TAG = toString();
     private final IImageDataReceiver imageView;
+    private byte[] imageData = null;
 
     /**
      * コンストラクタ
@@ -42,6 +47,24 @@ public class CameraLiveViewListenerImpl implements OLYCameraLiveViewListener, II
     }
 
     @Override
+    public @Nullable Bitmap getImage()
+    {
+        try
+        {
+            if (imageData == null)
+            {
+                return (null);
+            }
+            return (BitmapFactory.decodeByteArray(imageData, 0, imageData.length));
+        }
+        catch (Exception e)
+        {
+            e.printStackTrace();
+        }
+        return (null);
+    }
+
+    @Override
     public void setImageData(byte[] data, Map<String, Object> metadata)
     {
         // Log.v(TAG, " setImageData len : " + data.length);
@@ -49,5 +72,8 @@ public class CameraLiveViewListenerImpl implements OLYCameraLiveViewListener, II
         {
             imageView.setImageData(data, null);
         }
+        imageData = null;
+        imageData = data;
     }
+
 }