我工作的机器人,并尝试下载并在一个ImageView的显示来自网站图标(.ICO)。
I'm working on android and trying to download and display a favicon(.ICO) from a website on an ImageView.
到目前为止,我设法从使用HTTP连接一个网站读取。ICO,找回它作为一个InputStream。然后我用一个BitmapFactory脱code流成位图,并在ImageView的显示。这里的code:
So far I've manage to read the .ico from a website using an HTTP connection, retrieve it as an InputStream. Then I use a BitmapFactory to decode the stream into a Bitmap and display it on the ImageView. Here's 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;
}
}
的问题是,所述的InputStream的解码总是返回一个小16×16位图。如果我很好理解,一个.ico文件可以存储不同的图像分辨率,32×32像64×64和。我的问题是,有没有办法脱code中的32×32或64×64位图的16×16,而不是?
The problem is that the decoding of the inputStream always returns a small 16x16 Bitmap. If I well understood, a single .ICO file can store different image resolutions, like 32x32 and 64x64. My question is, is there a way to decode the 32x32 or the 64x64 Bitmap instead of the 16x16?
此外,如果没有与BitmapFactory的解决方案,是有图书馆或Java code做到这一点?
Also, if there isn't a solution with BitmapFactory, is there a library or java code to do this?
注意:我不想调整位图,我希望有一个32×32(或更大)的分辨率,不通过拉伸损失图像质量
NOTE: I don't want to resize the Bitmap, I want a 32x32(or bigger) resolution without losing the image quality by stretching.
先谢谢了。
推荐答案
该图标文件可能包含复式图标,通常是在16×16,一个在32×32。这是在下面的讨论主题:How有多个图标的大小,但在默认情况下只服务一个16x16?
The favicon file may contains mutliple icons, usually one in 16x16 and one in 32x32. This is discussed in the following thread : How to have multiple favicon sizes, yet serve only a 16x16 by default?
它与谷歌的favico的情况。如果您尝试下载的文件 www.google.com/favicon.ico ,并用它打开应用例如的IrfanView 上,您可以看到有两个图标(16×16到32×32)。
It is the case with the Google's favico. If you try to download the file www.google.com/favicon.ico and open it with an application like IrfanView, you can see that there are two icons (16x16 and 32x32).
要回答你的问题,你应该使用正确的库中提取多个图标,例如 image4j ,然后选择一个你需要的。
To answer your question, you should use a proper library to extract multiple icons, like image4j, and choose the one you need.
http://image4j.sourceforge.net/
相关推荐
最新文章