引用别人的回复,试了下,没问题了;
这个不是从sd卡读图片产生的问题,从sd卡读图片用 Bitmap bitmap = BitmapFactory.decodeFile(imagePath);是没有问题的,主要是你从服务器获取图片保存的时候出现的问题。
这个是HttpURLConnection的问题,如果使用apache的HttpClient的话,就不会有问题了,代码如下:
HttpGet httpRequest = new HttpGet(url);
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = (HttpResponse) httpclient.execute(httpRequest);
HttpEntity entity = response.getEntity();
BufferedHttpEntity bufferedHttpEntity = new BufferedHttpEntity(entity);
InputStream is = bufferedHttpEntity.getContent();
bitmap = BitmapFactory.decodeStream(is);
这里再一次证明了
apache的HttpClient比Java的HttpURLConnection强大