2011-07-05 22 views
0

我使用這個代碼來保存從屏幕截圖拍攝的位圖圖像:圖像不會在不同的Android設備保存

try{ 
    String fname = "/Pictures/YourApp/YourPic.jpg"; 
    File path= Environment.getExternalStorageDirectory(); 
    File file = new File(path, fname); 
    if (file.exists()) { 
       Bitmap bitty = BitmapFactory.decodeFile(file.toString()); 
        yourPlan.setImageBitmap(bitty); //ImageView 
      }else{ 
       errorText.setText("If you can not see your image then free up some memory"); 
      } 
     }catch(Exception e){ 
       errorText.setText("If you can not see your image then free up some memory"); 
     } 

它工作正常,在我測試的手機 - 在2.1橙色舊金山,但我有有來自用戶的電子郵件告訴我他們只有在保存足夠的空間時纔會收到錯誤消息。

他們正在使用HTC和三星手機。有任何想法嗎?

回答

0

首先,我想指出,捕捉一般Exception e是不是在良好的編碼習慣。其次,輸出給用戶的這兩條消息也沒有幫助,因爲不能保證錯誤與空間相關。

我猜錯誤來自文件不存在。你在哪裏保存文件?從代碼片段中,我發現你只是假設文件存在。如果您在拍攝屏幕後尚未保存文件,那就是您的問題。您正在打開一個不存在的文件,並且您的錯誤信息給人的印象是沒有足夠的空間。

相關問題