2014-08-27 93 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()而不是输出流