I would like to know if it is possible to use BitmapFactory.decodeFile method to decode a image from http location?
For eg.
ImageView imageview = new ImageView(context);
Bitmap bmp = BitmapFactory.decodeFile("http://<my IP>/test/abc.jpg");
imageview.setImageBitmap(bmp);
But bmp is always returning null.
Is there any other way to achieve this scenario, where i have a set of images in my server PC, and i am loading the images to my gallery application via an xml?
Thanks,
Sen
Use decodeStream and pass the URL's inputstream instead.
Here is an example:
Bitmap bmp = BitmapFactory.decodeStream(new java.net.URL(url).openStream())
@Amir & @Sankar : Thanks for your valuable suggestions.
I solved the above problem by doing the following code snippet :
ImageView iv = new ImageView(context);
try{
String url1 = "http://<my IP>/test/abc.jpg";
URL ulrn = new URL(url1);
HttpURLConnection con = (HttpURLConnection)ulrn.openConnection();
InputStream is = con.getInputStream();
Bitmap bmp = BitmapFactory.decodeStream(is);
if (null != bmp)
iv.setImageBitmap(bmp);
else
System.out.println("The Bitmap is NULL");
} catch(Exception e) {
}
Thanks,
Sen
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