本文介绍了在android中读取ICO文件以及所有子图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现,最好的建议是使用image4j.不幸的是,它在android下也不起作用,因为"IndexColorModel","BufferedImage"和"WritableRaster"类不可用.

I have found Is there a way to decode a .ICO file to a resolution bigger than 16x16? from 2 years ago and the best suggestion was to use image4j. Unfortunately it does not work under android in particular (also), because the classes "IndexColorModel", "BufferedImage" and "WritableRaster" are not available.

虽然通过将"BufferedImage"替换为"Bitmap"来解决问题,虽然可能可以工作并且不使用"WritableRaster",但是使用setPixel设置单个(或一组)像素也可以,但是我无法替换"IndexColorModel",因为我无法将其包裹住.

While working around "BufferedImage" by replacing it with "Bitmap" may perhaps work and not using "WritableRaster", but instead setting individual (or a group of) pixels using setPixel may work as well, I cannot manage to replace "IndexColorModel", because I cannot wrap my head around it.

我目前正在从一个网站上下载一个Favicon,该网站通常在其中存储多个图像.图像大小不同.我仔细阅读了ICO文件的结构,并尽可能地分析了image4j.但是我很难将各种类重构为不使用AWT.

I am currently downloading a favicon from a website, which stores usually more than one image inside of it. The images are of different size. I read up on the structure of ICO files and analyzed image4j as much as I could. Yet I have troubles refactoring the various classes to not use AWT.

BitmapFactory能够加载ICO文件;不幸的是,它仅加载第一张图像(至少是我的猜测),因此无法让我决定要加载哪个图像(更不用说全部加载并让我选择).

BitmapFactory is able to load ICO files; unfortunately it only loads the first image (this is my guess at least) and thus does not let me decide which image to load (let alone load them all and let me chose).

有人知道两年前是否有任何变化和/或有人愿意帮助我进行重构,例如还是image4j的BMPDecoder?

Does anyone know if anything changed from 2 years ago and/or would anyone be willing to help me refactor e.g. BMPDecoder from image4j? Or is there perhaps a totally different, easier approach to it?

推荐答案

我创建了一个基于image4j的库,该库允许将ICO文件读取到位图对象列表中.与image4j相反,ico4a不使用任何AWT类,而是仅使用Bitmap/Bitmap.createBitmap.

I have created a library based on image4j that will allow reading ICO files into a List of Bitmap-objects. In contrast to image4j ico4a does not use any AWT-classes, but instead only makes use of Bitmap / Bitmap.createBitmap.

请参见 https://github.com/divStar/ico4a .

虽然库的性能可能不是最好的,因为它在循环中使用了位图对象的setPixel方法,但它可以完成工作,对我来说已经足够了.

While the library's performance might not be the best as it uses a Bitmap-object's setPixel method in a loop, it gets the work done and it's good enough for me.

与image4j相比,我的库(ico4a)仅解码/读取文件.虽然保存ICO文件可能比较容易,但是我没有这样做,因为我自己不需要它.

In comparison to image4j my library (ico4a) only decodes/reads files. While saving ICO files could be done probably relatively easy, I have not done so since I do not need it myself.

如果您对库有其他疑问或问题,请将其发布到gitHub上,我会帮忙.

If you have further questions or issues with the library, post them on gitHub and I will see if I can help.

这篇关于在android中读取ICO文件以及所有子图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-13 06:55