有没有办法将.ICO文件解码为大于16x16的分辨率?

Dav*_*eto 5 java android bitmap ico

我正在研究android并试图从ImageView上的网站下载并显示一个favicon(.ICO).

到目前为止,我已经设法使用HTTP连接从网站读取.ico,将其作为InputStream检索.然后我使用BitmapFactory将流解码为Bitmap并将其显示在ImageView上.这是代码:

 public Bitmap getBitmapFromURL(URL src) {           
        try {

            URL url = new URL("http", "www.google.com", "/favicon.ico");

            HttpURLConnection connection = (HttpURLConnection) url.openConnection();                

            connection.setDoInput(true);       

            connection.connect();               

            InputStream input = connection.getInputStream();    

            BitmapFactory.Options options = new BitmapFactory.Options();

            Bitmap myBitmap = BitmapFactory.decodeStream(input, null, options);  

            return myBitmap;

        } catch (IOException e) {               
            e.printStackTrace();                
            return null;                
        }
    }
Run Code Online (Sandbox Code Playgroud)

问题是inputStream的解码总是返回一个小的16x16位图.如果我很好理解,单个.ICO文件可以存储不同的图像分辨率,如32x32和64x64.我的问题是,有没有办法解码32x32或64x64位图而不是16x16?

另外,如果没有BitmapFactory的解决方案,是否有库或ja​​va代码来执行此操作?

注意:我不想调整位图的大小,我想要一个32x32(或更大)的分辨率,而不会通过拉伸损失图像质量.

提前致谢.

小智 1

favicon 文件可能包含多个图标,通常一个为 16x16,一个为 32x32。这将在以下主题中讨论:如何拥有多个图标大小,但默认情况下仅提供 16x16?

Google 的 favico 就是这种情况。如果您尝试下载文件www.google.com/favicon.ico并使用IrfanView等应用程序打开它,您可以看到有两个图标(16x16 和 32x32)。

要回答您的问题,您应该使用适当的库来提取多个图标(例如image4j ),然后选择您需要的图标。

http://image4j.sourceforge.net/