2014-10-29 105 views
1

我的情況如下:我正在將多個位圖從陣列列表保存到我的設備中的特定文件夾SD卡(成功),但保存的文件 - 當點擊 - 從手機提示消息,指出:「無法找到應用程序來執行此操作。」此文件的文件大小與正在保存的位圖圖像的文件大小成正比,所以我有點困惑,因爲設備沒有打開圖像文件的問題,但無法打開(或識別)這些文件作爲媒體文件。將位圖從ArrayList保存到SD卡 - 保存的文件無法讀取

問題:什麼會導致保存的圖像文件(假設我已經保存正確)在設備中顯示這種類型的行爲,我該如何解決此問題?

額外:文件的縮略圖是系統提供的兩張紙的縮略圖。 ArrayList從一個活動傳遞到當前提供的方法。

這裏是調用的文件保存到指定文件夾/ filesdestination方法:

private void saveImages(){ 
// to retrieve bitmaps 
    ArrayList<Bitmap> images = getIntent().getParcelableArrayListExtra("images key"); 
//to retrieve bitmaps and save in specific order, while also naming them in that order 
    int loopVal = 0; 
    int postVal = 9; 
    while (loopVal < 9) { 
     Bitmap Image = images.get(loopVal); 
    try { 

     String filedestination = new String(Environment.getExternalStorageDirectory() + "/filedestination"); 
     String timeStamp = new SimpleDateFormat("ddMMyyyy_HHmm").format(new Date()); 
     File file = new File(filedestination, postVal + ".post_order" + ".jpg" + timeStamp); 
     File picfile = file; 
     FileOutputStream fos = new FileOutputStream(picfile); 
      Image.compress(Bitmap.CompressFormat.PNG, 100, fos);  
      fos.close(); 



    } catch (Throwable e) { 

     e.printStackTrace(); 

    } 
    postVal--; 
    loopVal++; 

    } 


} 

任何有識之士將不勝感激我認爲它無法讀取,

-Lucas

回答

0

文件類型,因爲時間戳是在文件擴展名jpg之後,並且您也將其壓縮爲png,所以您可能想要更改其中一個或類似的內容

File file = new File(filedestination, postVal + timeStamp +".post_order" + ".png"); 
+0

這工作!我現在知道.jpg的.png位置在跨應用程序可讀性方面有多重要,謝謝! – Lucas 2014-10-30 00:45:10

+0

您的歡迎,很高興能夠得到幫助:) – JRowan 2014-10-30 00:57:27

0

看來您正在保存一個壓縮爲PNG的.jpg文件。這可能會使圖像閱讀器應用程序行爲失常。

要麼改變Image.compress(Bitmap.CompressFormat.PNG, 100, fos);

Image.compress(Bitmap.CompressFormat.JPEG, 100, fos);

變化

File file = new File(filedestination, postVal + ".post_order" + ".jpg" + timeStamp);

File file = new File(filedestination, postVal + ".post_order" + ".png" + timeStamp);

+0

我試過了,但是發生過相同的情況:/ – Lucas 2014-10-30 00:43:30

+0

是的,我錯過了延期之後的時間戳,就像其他答案指出的那樣。 :) – MadEqua 2014-10-30 00:51:50