I have tried to get the bitmap image from the path of the image. But BitmapFactory.decodeStream
returns null
value.
Code:
U
using the following code iam able to download an image from the url
String IMAGE_URL = "http://www.kolkatabirds.com/rainquail8vt.jpg";
//where we want to download it from
URL url;
try {
url = new URL(IMAGE_URL);
//open the connection
URLConnection ucon = url.openConnection();
//buffer the download
InputStream is = ucon.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is,1024);
//get the bytes one by one
int current = 0;
while ((current = bis.read()) != -1) {
baf.append((byte) current);
}
//convert it back to an image
ByteArrayInputStream imageStream = new ByteArrayInputStream(baf.toByteArray());
Bitmap theImage = BitmapFactory.decodeStream(imageStream);
img.setImageBitmap(theImage);