1

I am using following method to download image from URL

private Bitmap getBitmap(String url) 
    {
        File f=fileCache.getFile(url);
        Log.d("getBitmap", "getBitmap"+url);
        //from SD cache
        Bitmap b = decodeFile(f);
        if(b!=null)
            return b;

        //from web
        try {
            Bitmap bitmap=null;
            URL imageUrl = new URL(url);

            HttpURLConnection conn = (HttpURLConnection)imageUrl.openConnection();
            conn.setConnectTimeout(30000);
            conn.setReadTimeout(30000);
            conn.setInstanceFollowRedirects(true);
            InputStream is=conn.getInputStream();
            OutputStream os = new FileOutputStream(f);
            Utils.CopyStream(is, os);
            os.close();

            bitmap = BitmapFactory.decodeStream(is);
            return bitmap;
        } catch (Exception ex){
            ex.printStackTrace();
            return null;
        }
    }

for me this method is working well for all URLs which correspond to an Image But the problem is that it does not work for following

http://downloads.hyperin.com/hyperin-portal/imageserver/news/13442/ginatricot.jpg

Working well for following url

http://downloads.hyperin.com/hyperin-portal/imageserver/news/12042/Myfit_liity_nyt.jpg

For debugging i opened image in browser and downloaded it on my PC checked its properties and figured out that this is 32 bit Image and other images which are downloaded successfully are 24 bit. I don't know why same code cannot download 32 bit image which is successfully downloading 24 bit image. I my code missing something? Does android not support 32 bit Images? Or What? Please Suggest me figuring out solution

3 Answers3

0

http://downloads.hyperin.com/hyperin-portal/imageserver/news/13442/ginatricot.jpg

cant work for this one.. theres no pic ^^

Eveli
  • 498
  • 1
  • 6
  • 27
0

Do not reinvent the wheel, try this https://github.com/koush/UrlImageViewHelper

Roger Garzon Nieto
  • 6,554
  • 2
  • 28
  • 24
  • I tried this library but this doesn't also help downloading http://downloads.hyperin.com/hyperin-portal/imageserver/news/13442/ginatricot.jpg – QAMAR Jan 31 '13 at 17:15
0
public static Bitmap getImagefromURL(String url) {
HttpURLConnection connection  = (HttpURLConnection) url.openConnection();
InputStream is = connection.getInputStream();
Bitmap img = BitmapFactory.decodeStream(is);  
return img;
}
Jambaaz
  • 2,788
  • 1
  • 19
  • 30
  • this solution works, but not for http://downloads.hyperin.com/hyperin-portal/imageserver/news/13442/ginatricot.jpg – QAMAR Jan 31 '13 at 17:14