我将Handler与ImageReader配合使用,以便在背景中获取图像。
但我得到:


 private final ImageReader.OnImageAvailableListener mOnImageAvailableListener
        = new ImageReader.OnImageAvailableListener() {

    @Override
    public void onImageAvailable(ImageReader reader) {
        mBackgroundHandler.post(new ImageSaver(reader.acquireNextImage(), CameraFragment.this));
    }

};

在我的后台任务是:
    private static class ImageSaver implements Runnable {

    /**
     * The JPEG image
     */
    private final Image mImage;

    BaseCameraFragment cameraFragmentContext;

    public ImageSaver(Image image, BaseCameraFragment cameraFragmentContext) {
        mImage = image;
        this.cameraFragmentContext = cameraFragmentContext;
    }

    @Override
    public void run() {
        ByteBuffer buffer = mImage.getPlanes()[0].getBuffer();
        cameraFragmentContext.photoReady(new ByteBufferInputStream(buffer));
        mImage.close();
    }

}

我该如何解决这个问题?

最佳答案

`

private ImageReader.OnImageAvailableListener imageAvailableListener = new ImageReader.OnImageAvailableListener()
{
    @Override
    public void onImageAvailable(ImageReader reader) {
        Image img = mReader.acquireLatestImage();

        //mReader.close();
       img.close();
    }
};

`

只需使用img.close();就可以解决它

10-06 09:33