3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

CameraXでImageProxyを扱おうとすると 'Image is already closed' でクラッシュする

Posted at

はじめに

CameraXで撮影した画像をBitmapに変換しようとした時に以下のエラーで苦しめられたのでメモっておきます。

java.lang.IllegalStateException: Image is already closed

かいけつ

撮影時のリスナーである onCaptureSuccess 内でコンストラクタを呼んでたのが原因でした。

failed

override fun onCaptureSuccess(image: ImageProxy?, rotationDegrees: Int) {
    super.onCaptureSuccess(image, rotationDegrees)
    // do
}

success

override fun onCaptureSuccess(image: ImageProxy?, rotationDegrees: Int) {
    // do
}

なんでか

onCaptureSuccess の内部の実装を見ると中で ImageProxyclose させていたためでした。

ImageCapture.java
public void onCaptureSuccess(ImageProxy image, int rotationDegrees) {
            image.close();
        }

おわりに

ちゃんと使うなら標準ライブラリ使えよってことですかね・・・

3
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?