我正在尝试从原始质量的互联网下载图像。然后尝试使用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();
}
}
答案 0 :(得分:1)
您应该将文件名传递给函数BitmapFactory.decodeFile()
而不是输出流