【发布时间】:2014-06-22 09:58:04
【问题描述】:
我用“imgUrl”保存我下载图片的URL,用“BitmapFactory”缩小而不浪费RAM,但是因为有几张图片,所以需要很多,你知道更好的方法吗?.
public class DownloadImage extends AsyncTask<Object, Void, Bitmap> {
ImageView imagen;
String imgUrl="";
Bitmap bitm;
protected Bitmap doInBackground(Object... params){
imgUrl = (String) params[0];
imagen = (ImageView) params[1];
try {
URL imageUrl = new URL(imgUrl); /*Using the URL for download the image*/
HttpURLConnection conn = (HttpURLConnection) imageUrl.openConnection();
conn.connect();
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 3;
bitm = BitmapFactory.decodeStream(conn.getInputStream(), new Rect(0, 0, 0, 0), options);
} catch (IOException e) {
Log.e("catch", e+"");
}
return bitm;
}
protected void onPostExecute(Bitmap result){
imagen.setImageBitmap(result);
super.onPostExecute(result);
}
}
【问题讨论】:
标签: android image optimization android-asynctask