1

我的应用程序从图库中获取图像并复制到子文件夹。但是,复制的图像作为来自不同位置的原始图像的副本进入画廊。

如何预防?请帮我。

这是我保存到预定义文件夹的代码....

protected String saveBitmap(Bitmap bm, String path) throws Exception {
    String tempFilePath="/sdcard/AuFridis/Events/Images/"+System.currentTimeMillis()+"myEventImg.jpg";
    File tempFile = new File(path+"/"+System.currentTimeMillis()+"myEventImg.jpg");
   // File tempFile = new File("/sdcard/Notes");
    tempFile.createNewFile();

    if (!tempFile.exists()) {
        if (!tempFile.getParentFile().exists()) {
            tempFile.getParentFile().mkdirs();
        }
    }

    //tempFile.delete();
    //tempFile.createNewFile();

    int quality = 100;
    FileOutputStream fileOutputStream = new FileOutputStream(tempFile);

    BufferedOutputStream bos = new BufferedOutputStream(fileOutputStream);
    bm.compress(CompressFormat.JPEG, quality, bos);

    bos.flush();
    bos.close();

    //bm.recycle();
    Log.i("On saveBitmap Function - retrieved file path", "---"+tempFilePath);
    return tempFilePath;

}
4

2 回答 2

0

默认情况下,android 会扫描 SD 卡并将找到的所有图像添加到图库中。如果您将图像从图库复制到另一个文件夹,该文件夹将自动添加到图库。为防止这种情况发生,请在您的目标文件夹中添加一个带有名称的空文件.nomedia- 您复制的图像将不会显示在图库中。

于 2013-10-15T16:08:07.040 回答
0

您是否要从图库中隐藏图像?默认情况下,Android 会扫描设备的内存并将找到的所有照片放入图库。该设备很可能会看到重复的名称和标签。只需更改图像名称。

于 2013-10-15T16:01:50.267 回答