查了很多文章,发现不是网络图片转化bitmap时出现问题;
然后想到 是否为图片尺寸过大而导致的.
public static Bitmap http2BitMap(final String url){
Bitmap bm = null;
Bitmap scaledBitmap = null;
try {
URL iconUrl = new URL(url);
URLConnection conn = iconUrl.openConnection();
HttpURLConnection http = (HttpURLConnection) conn;
int length = http.getContentLength();
conn.connect();
// 获得图像的字符流
InputStream is = conn.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is, length);
bm = BitmapFactory.decodeStream(bis);
scaledBitmap = Bitmap.createScaledBitmap(bm, 340, 340, true);//此为改变bitmap大小
bis.close();
is.close();// 关闭流
}
catch (Exception e) {
e.printStackTrace();
}
// return compressBitmap(scaledBitmap,2048);
return scaledBitmap;
}
Bitmap.createScaledBitmap(bm, 340, 340, true);//此为改变bitmap大小
运用此句可对bitmap大小进行设置
运行后发现问题解决!