Java – is there any way to ICO file decoded to be greater than 16 × 16 resolution?

I'm studying Android and trying to download and display a favicon (. ICO) from the website on ImageView

So far, I have managed to read from the website using HTTP connection ICO to retrieve it as an InputStream Then I use bitmapfactory to decode the stream into bitmap and display it on ImageView This is the code:

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;                
        }
    }

The problem is that the decoding of InputStream always returns a small 16 × 16 bitmap If I understand it well, I can't understand it ICO files can store different image resolutions, such as 32 × 32 and 64 × 64. My question is, is there any way to decode 32 × 32 or 64 × 64 bitmap instead of 16 × 16?

In addition, if there is no bitmapfactory solution, is there a library or Java code to perform this operation?

Note: I don't want to resize the bitmap. I want a 32 × 32 (or greater) resolution without losing image quality by stretching

Thank you in advance

Solution

I know this question was asked three years ago, but I encountered the same problem and adapted part of image4j into ico4a. You can find it here: https://github.com/divStar/ico4a (I wrote it myself because I want to load the largest image from an icon; because image4j uses AWT class, which is not easy to obtain for Android, I did so. Ico4a mainly uses the native Android class)

It can decode most valid ICO files into a list of bitmap objects I believe the library itself or the sample application also has a way to retrieve the largest bitmap object

However, my library cannot write ICO files; It can only read them Despite the use of some built-in Android features, you can easily save individual images as PNG or JPEG graphics

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>