ImageReader on Android is blocking

2.4k views Asked by At

I would like to implement an Image Reader but it blocks at the first image reading.

I really don't know how to unlock the situation.

Surface processSurface = reader.getSurface();
surfaces.add(processSurface);
recordRequestBuilder.addTarget(processSurface);

reader.setOnImageAvailableListener(new ImageReader.OnImageAvailableListener() {
    @Override
    public void onImageAvailable(ImageReader reader) {
      Log.v("ImageReader","Reading");
    //I want to do a process on the image here, but i don't want to 
    //block my UI
    }
},null);

I don't understand, if I write reader.aquireLatestImage or reader.aquireNextImage, it tell me to close the reader.

If I do a reader.close after, I got this:

BufferQueue has been abandoned

2

There are 2 answers

1
Robert Navado On

If you don't want to block your GUI for time-consuming operations you can run tasks in background. You can use AsyncTasks and Handlers (http://www.vogella.com/tutorials/AndroidBackgroundProcessing/article.html) or follow one of best practices for Android: https://developer.android.com/training/best-background.html

0
Widea On

Ok, i finally found what was the problem.

reader.setOnImageAvailableListener(new ImageReader.OnImageAvailableListener() {
            @Override
            public void onImageAvailable(ImageReader reader) {
                Image mImage = reader.acquireNextImage();
                /**
                 * TODO
                 * Image Process
                 */

                mImage.close();
            }
        },null);