Android Camera2 API - 覆盖旧图像

Android Camera2 API - Overwrite old images

我正在使用 https://github.com/googlesamples/android-Camera2Basic 中给出的代码 图像被保存在 activity 存储中

    @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) 来显示图像,库根据图像名称缓存图像。虽然新图像已存储在设备上,但已显示缓存的旧图像。