模拟器没问题 motoME722真机测试 bm.compress(Bitmap.CompressFormat.PNG, 100, os);报NullPointerException
log日志是以warn的形式报的。
URL url = new URL(urlStr);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
is = conn.getInputStream();
if(is==null){
return null;
}
Bitmap bm = BitmapFactory.decodeStream(is);
os = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.PNG, 100, os);
log日志是以warn的形式报的。
URL url = new URL(urlStr);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
is = conn.getInputStream();
if(is==null){
return null;
}
Bitmap bm = BitmapFactory.decodeStream(is);
os = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.PNG, 100, os);
这里的bm是null吧。
你is都做了判断了, bm也做一次判断吧
所以NullPointerException
Since: API Level 1Decode an input stream into a bitmap. If the input stream is null, or cannot be used to decode a bitmap, the function returns null. The stream's position will be where ever it was after the encoded data was read.
Parameters
is The input stream that holds the raw data to be decoded into a bitmap.
Returns The decoded bitmap, or null if the image data could not be decoded.
return null;
}
如果是null,Bitmap当然可以为空。
If the input stream is null, or cannot be used to decode a bitmap, the function returns null如果is不为null,说明input stream 不能转码成bitmap 则返回null
http://www.cnblogs.com/ixyx/archive/2011/04/07/Bitmap_decode.html
具体不能解码的原因我也不确定,应该不是参见网址里说的版本问题,
InputStream is=conn.getInputStream();
bm=BitmapFactory.decodeStream(is);
这种写法貌似小图片没问题,图片一大就有问题,大图片要换成getbytes方式。