【问题标题】:Get 32px favicon.ico获取 32px favicon.ico
【发布时间】:2013-02-26 18:56:02
【问题描述】:

我试图获取网站的 32px favicon.ico,但它获得的响应是​​ 16px 的 favicon,我想是因为我试图通过智能手机获取它,但我尝试更改用户代理没有结果的 http 请愿书是我的代码:

DefaultHttpClient client = new DefaultHttpClient();
            String baseUrl = getBaseUrl(url);
            HttpGet httpGet = new HttpGet(baseUrl + "/favicon.ico");
            httpGet.setHeader("User-Agent", "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1025.45 Safari/535.19");
            HttpResponse httpResponse = null;
            try {
                httpResponse = client.execute(httpGet);
            } catch (ClientProtocolException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }catch (NullPointerException e) {
                e.printStackTrace();
            }
            InputStream is = null;
            try {
                is = (java.io.InputStream) httpResponse.getEntity().getContent();
            } catch (IllegalStateException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (NullPointerException e) {
                e.printStackTrace();
            }
            Drawable favicon = Drawable.createFromStream(is, "src");
            final BitmapDrawable bd = (BitmapDrawable) favicon;

知道如何获得它吗? 谢谢

【问题讨论】:

    标签: android httprequest user-agent favicon


    【解决方案1】:

    .ico 文件可以包含多张图片。因此,您获得的favicon.ico 文件很可能包含一张 16x16 的图片一张 32x32 的图片。

    您可以使用icotool 命令行工具来分析.ico 文件:

    # On Ubuntu
    sudo apt-get install icoutils
    icotool -l favicon.ico
    --icon --index=1 --width=16 --height=16 --bit-depth=32 --palette-size=0
    --icon --index=2 --width=32 --height=32 --bit-depth=32 --palette-size=0
    --icon --index=3 --width=48 --height=48 --bit-depth=32 --palette-size=0
    # 3 pictures in this favicon.ico file
    

    在 Windows 上,当您使用默认查看器(只需双击文件)打开 .ico 文件时,查看器可让您浏览文件中包含的多张图片。它不会打印他们的分辨率,但至少你知道你的奇怪行为是怎么回事。

    【讨论】:

      【解决方案2】:

      智能手机无法做到这一点。实际上在某些网站图标大小为 16 像素,而其他网站图标大小为 32 像素。 像 facebook、google、twitter 一样有 16px favicon 还有 yahoo、google plus 有 32 px favicon...

      【讨论】:

        猜你喜欢
        • 2012-06-20
        • 2021-12-17
        • 1970-01-01
        • 2014-10-18
        • 2012-03-28
        • 1970-01-01
        • 2015-02-05
        • 2016-04-13
        • 1970-01-01
        相关资源
        最近更新 更多