如下面的代码所示,我将位图保存到公共图片目录中。我还提供了存储中图像的屏幕截图,以进一步证明正在保存图像。

问题在于,直到我重新启动手机,图像才会显示在“照片”应用程序中。我已经检查了其他应用程序,这些图片会立即显示。如果我打开图片,也无法像其他图片一样对其进行编辑(例如添加效果)。



 Bitmap b = Bitmap.createScaledBitmap(mBitmap, width, height, false);

                Long uuid = UUID.randomUUID().getMostSignificantBits();
            File path = Environment.getExternalStoragePublicDirectory(
                    Environment.DIRECTORY_PICTURES + "/test");

            if(!path.exists() && !path.isDirectory()){
                path.mkdirs();
            }

            Log.i("Directory:", path.toString());

            File file = new File(path, "test_" + uuid + ".jpg");

            if (file.exists()){
                file.delete();
            }

            FileOutputStream out = null;
            try {
                out = new FileOutputStream(file);
                b.compress(Bitmap.CompressFormat.JPEG, 80, out);

            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                try {
                    if (out != null) {
                        out.close();
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }

        }
    });

最佳答案

添加新图像时必须发送通知

getContentResolver().notifyChange(
    Uri.parse("file://sdcard/abc.png");

07-28 02:15