2013-10-15 67 views
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; 

} 
+0

所以現在在畫廊你看到圖像兩次?一個是原創的,另一個是通過你的應用程序複製的? –

回答

0

你試圖隱藏從圖庫中的圖片? Android默認掃描設備的內存,並將其找到的所有照片放入畫廊。該設備很可能會看到重複的名稱和標籤。只需更改圖像名稱即可。

0

默認情況下,android會掃描SD卡並將找到的所有圖像添加到圖庫中。如果您將圖庫中的圖像複製到另一個文件夾,該文件夾將自動添加到圖庫中。爲防止出現這種情況,請將名爲.nomedia的空文件添加到目標文件夾 - 並且您的複製圖像不會顯示在圖庫中。

+0

你能解釋一下更多.. plz .. wats this .nomedia ?? – nafi

+0

android會在每當其內容發生更改時掃描SD卡,並自動將其找到的每個圖像和視頻添加到圖庫中。應用程序可以選擇阻止其媒體被索引/添加 - 如果android在文件夾中看到一個名爲'.nomedia'的文件,那麼它將跳過該文件夾,並且該文件夾中的圖像和視頻將不會被掃描/索引/添加到圖庫。 –