下载图片比较简单 不过有个需要注意的是下载的图片不能太大要不然BitmapFactory在创建BItmap的时候会报OutOfMemoryError这个错
下面上代码
public Bitmap readImageBitmap(String downUrl) {
Bitmap bitmap = null;
HttpURLConnection conn=null;
try {
URL url = new URL(downUrl);
conn = (HttpURLConnection) url.openConnection();
conn.setDoInput(true);
conn.connect();
InputStream inputStream = conn.getInputStream();
BitmapFactory.Options opt = new BitmapFactory.Options();
opt.inPreferredConfig = Bitmap.Config.RGB_565;
opt.inPurgeable = true;
opt.inInputShareable = true;
bitmap = BitmapFactory.decodeStream(inputStream,null,opt);
} catch (MalformedURLException e1) {
e1.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return bitmap;
}
如果有哪位大侠知道如何处理加载图片过大因BItmap而引起的OutOfMemoryError的方法 麻烦留个言 谢谢!!!!