Android Fill ImageView From URL
Hi i'm trying to add an image to an ImageView from a URL i have tried loading it as a bitmap but nothing is showing. so does anyone know what the best method to do this is or what
Solution 1:
Please use this code spinet convert url images to bitmap and show it in image view .
URL url = new URL("http://image10.bizrate-images.com/resize?sq=60&uid=2216744464");
Bitmap bmp = BitmapFactory.decodeStream(url.openConnection().getInputStream());
imageView.setImageBitmap(bmp);
T think it help you.
Thanks
Solution 2:
I use Prime for all of my image loading, is handles situations like this with ease.
Solution 3:
String url1 = "Your URL....";
URL ulrn = new URL(url1);
HttpURLConnection con = (HttpURLConnection) ulrn
.openConnection();
InputStream is = con.getInputStream();
bmp1 = BitmapFactory.decodeStream(is);
int widthPx = 150; //you can set width
int heightPx = 150; //you can set height
bmp1=Bitmap.createScaledBitmap(bmp1, widthPx, heightPx, true);
Imgview1.setImageBitmap(bmp1);
Solution 4:
In situation like this I'd try to write the InputStream into a file first then load from file. That usually works. Another reason to justify writing into file is because I prefer to lazy load the image from internet as it could take much longer than expected. In this case, I suspect that the InputStream was closed before it has a chance to finish the process.
Yours code and mine structured pretty much the same without the copying into file part.
If you wish to investigate, I'd recommend you doing this:
- Check that the image is actually exists.
- Check and compare size of the Stream and Bitmap.
- Check the InpuStream to see if it was closed unexpectedly.
Post a Comment for "Android Fill ImageView From URL"