Android: bitmapfactory.decodestream returns null
Got a Solution :
HttpGet httpRequest = new HttpGet(URI.create(path) );
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = (HttpResponse) httpclient.execute(httpRequest);
HttpEntity entity = response.getEntity();
BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(entity);
bmp = BitmapFactory.decodeStream(bufHttpEntity.getContent());
httpRequest.abort();
The problem was that once you've used an InputStream
from a HttpUrlConnection
, you can't rewind and use the same InputStream
again. Therefore you have to create a new InputStream
for the actual sampling of the image. Otherwise we have to abort the HTTP
request.