1

次の方法を使用して、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;
        }
    }

私にとって、この方法は画像に対応するすべての URL でうまく機能しますが 問題は次の URL では機能しないことです。

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

次のURLでうまく機能しています

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

デバッグのために、ブラウザーで画像を開き、PC にダウンロードしてそのプロパティを確認し、これが 32 ビットの画像であり、正常にダウンロードされた他の画像が 24 ビットであることがわかりました。同じコードで、24 ビット イメージを正常にダウンロードしている 32 ビット イメージをダウンロードできない理由がわかりません。私のコードに何か欠けていますか?Android は 32 ビット イメージをサポートしていませんか? または何?解決策を考え出すことを提案してください

4

3 に答える 3

0
public static Bitmap getImagefromURL(String url) {
HttpURLConnection connection  = (HttpURLConnection) url.openConnection();
InputStream is = connection.getInputStream();
Bitmap img = BitmapFactory.decodeStream(is);  
return img;
}
于 2013-01-31T15:41:31.120 に答える
0

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

これのために働くカント.. Theres の写真 ^^

于 2013-01-31T14:58:59.260 に答える
0

車輪を再発明しないでください。これを試してください https://github.com/koush/UrlImageViewHelper

于 2013-01-31T15:20:08.940 に答える