I have tried to get the bitmap image from the path of the image. But BitmapFactory.decodeStream
returns null
value.
Code:
URL url = new URL(path);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
Bitmap myBitmap = BitmapFactory.decodeStream(input);
connection.disconnect();
input.close();
I have searched in more sites, still i did not get the solution.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With