2014-08-27 16 views
0

我想以原始質量從互聯網上下載圖像。然後試圖BitmapFactory.decodeFile()來獲取位圖如何使用BitmapFactory.decodeFile()獲取位圖

執行此任務的我試過,但我收到此錯誤:

The method decodeFile(String) in the type BitmapFactory is not applicable for the arguments (FileOutputStream)

代碼:

public void saveImageToSDCard(Bitmap bitmap) { 
     String dirname = "/Amazing Wallpapers/"; 

     File myDir = new File(Environment.getExternalStorageDirectory() 
       .getPath() + dirname); 

     myDir.mkdirs();  
     String str = currentUrl.substring(currentUrl.lastIndexOf('/') + 1, 
       currentUrl.length()); 

     String fname = "Wallpaper-" + str + ".jpg"; 
     File file = new File(myDir, fname); 
     if (file.exists()) 
      file.delete(); 
     try { 
      FileOutputStream out = new FileOutputStream(file); 
      bitmap = BitmapFactory.decodeFile(out); 
      out.flush(); 
      out.close(); 
      Toast.makeText(
        _context, 
        _context.getString(R.string.toast_saved).replace("#", 
          "\"" + pref.getGalleryName() + "\""), 
        Toast.LENGTH_SHORT).show(); 
      Log.d(TAG, "Wallpaper saved to:" + file.getAbsolutePath()); 

     } catch (Exception e) { 
      e.printStackTrace(); 
      Toast.makeText(_context, 
        _context.getString(R.string.toast_saved_failed), 
        Toast.LENGTH_SHORT).show(); 
     } 
    } 

回答

1

你應該將文件名傳遞給函數BitmapFactory.decodeFile()而不是輸出流