Android Camera2 API - 覆盖旧图像

朱利安

我正在使用https://github.com/googlesamples/android-Camera2Basic 上给出的代码,并且图像被保存在活动存储中

    @Override
    public void run() {
        ByteBuffer buffer = mImage.getPlanes()[0].getBuffer();
        byte[] bytes = new byte[buffer.remaining()];
        buffer.get(bytes);
        FileOutputStream output = null;
        try {
            output = new FileOutputStream(mFile, false);
            output.write(bytes);
            output.flush();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            mImage.close();
            if (null != output) {
                try {
                    output.close();
                    buffer.clear();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

由示例代码给出。如果我删除图像

   File image_directory = getFilesDir();
    if (image_directory != null) {
        File[] images_list = image_directory.listFiles();
        for (int i = 0; i < images_list.length; i++) {
            try {
                //Delete the images files in the given folder
                images_list[i].delete();
                Log.e(TAG, "[-] File deleted with filename: " + images_list[i].getName());
            } catch (Exception e) {
            }
        }
    }

并使用与以前相同的文件名拍摄新图像,旧图像显示。这里发生了什么?

朱利安

好的,代码正确。我正在使用 Glide ( https://github.com/bumptech/glide ) 来显示图像,并且库根据图像名称缓存了图像。虽然新图像已存储在设备上,但已显示缓存的旧图像。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章