我正在使用Async任务下载其他一些数据,而Async任务执行时我想将图像从网址保存到SD卡中。那么在不使用异步任务的情况下,将图像保存到SD卡的最快方式或任何替代方法是什么。我搜索了Google和stackoverflow,但无法找到合适的解决方案。
答案 0 :(得分:0)
touchView.setDrawingCacheEnabled(true);
Bitmap bitmap = touchView.getDrawingCache();
File file = new File(Environment.getExternalStorageDirectory()
+ "/MultiTouchView_Image.png");
if (file.exists())
file.delete();
try {
if (!file.exists()) {
file.createNewFile();
}
FileOutputStream ostream = new FileOutputStream(file);
bitmap.compress(CompressFormat.PNG, 10, ostream);
ostream.close();
touchView.invalidate();
} catch (Exception e) {
Log.e(TAG, "Save fail!");
e.printStackTrace();
} finally {
Log.e(TAG, "Save successfull!");
touchView.setDrawingCacheEnabled(false);
touchView.invalidate();
}
TouchView:您要保存到图像的视图。
答案 1 :(得分:0)
Aquery是下载图片的最快,最轻松的方式。
如需更多参考,请点击此处http://androiddhina.blogspot.in/2015/03/androiddownload-image-using-aquery.html