Android高效存储两张相似的图像

发布于 2024-12-06 15:30:22 字数 311 浏览 0 评论 0原文

手机上的应用程序大小需要尽可能小。如果我有一把剑的图像,然后是同一把剑的非常相似的图像,除了我改变了颜色或添加了火焰或改变了珠宝的图片或其他什么,如何尽可能有效地存储东西?

一种可能性是以图形方式存储差异。我只存储图像差异,然后在运行时组合两个图像。我已经在图形设计 stackexchange 网站上问了一个关于如何做到这一点的问题。

另一种可能性是 apk 已经做到了这一点,或者已经有一种文件格式或方法人们用来在 android 中存储类似的图像。

有什么建议吗?是否有工具可以用来获取两个 png 并生成差异文件或用于存储相似图像或其他内容的文件格式?

Application size on a phone needs to be as small as possible. If I have an image of a sword and then a very similar image of that same sword except that I've changed the color or added flames or changed the picture of the jewel or whatever, how do store things as efficiently as possible?

One possibility is to store the differences graphically. I'd store just the image differences and then combine the two images at runtime. I've already asked a question on the graphic design stackexchange site about how to do that.

Another possibility would be that there is that apk already does this or that there is already a file format or method people use to store similar images in android.

Any suggestions? Are there tools that I could use to take two pngs and generate a difference file or a file format for storing similar images or something?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

永言不败 2024-12-13 15:30:22

我会在更高的层面上解决这个问题。例如,在运行时更改颜色(可能使用非常特定的颜色存储图像,例如一些丑陋的绿色阴影,您知道它是在运行时用白色、红色或蓝色或任何实际颜色固定的颜色你想要)。然后您可以在加载时生成多个图像缓冲区。

为了合成两个图像,只需单独存储“宝石”图像,并将其绘制在基本剑上。同样,您可以在加载时创建一个新图像,或者只是在运行时进行过度绘制。

这将有助于减少应用程序在闪存上的占用空间,但不会减少应用程序处于活动状态时的内存占用空间。

I'd solve this problem at a higher level. For example, do the color change at run-time (maybe store the image with a very specific color like some ugly shade of green that you know is the color to be fixed at run-time with white or red or blue or whatever actual color you want). Then you could generate several image buffers at load-time.

For compositing the two images, just store the 'jewel' image separately, and draw it over the basic sword. Again, you could create a new image at load-time, or just do the overdraw at run-time.

This will help reduce your application's footprint on flash, but will not reduce the memory footprint when the app is active.

惜醉颜 2024-12-13 15:30:22

我相信你存储两个图像之间的增量的想法非常好。

然后,您可以使用简单的熵编码器(例如霍夫曼)压缩生成的增量文件,如果与基本图像的相似性很重要,那么您很可能会获得很高的压缩比。

如果相似性确实非常强,您甚至可以尝试使用范围编码器,以实现每像素不到一位的性能。然而,只有对于较大的图像(即比 12x12 精灵更高的清晰度),差异可能才明显。

然而,这些想法将要求您或某人为您编写此类函数的代码。这应该是非常简单的。

I believe your idea of storing the delta between 2 images to be quite good.

You would then compress the resulting delta file with a simple entropy coder, such as Huffman, and you are pretty likely to achieve a strong compression ratio if similarities with base image are important.

If the similarity are really very strong, you could even try a Range Coder, to achieve less-than-one-bit-per-pixel performance. The difference however might be noticeable only for larger images (i.e higher definition than a 12x12 sprite).

These ideas however will require you or someone to write for you such function's code. This should be quite straightforward.

她说她爱他 2024-12-13 15:30:22

实现此目的的一个非常简单的方法是使用 ImagePack(一个图像包含多个图像) - 这样您就可以轻松地利用 PNG 或 JPG 压缩算法来达到您的目的。然后在绘制之前分割图像。

An very easy approach to do this is to use an ImagePack ( one image containing many ) - so you can easy leverage the PNG or JPG compression algorithms for your purpose. You then split the images before drawing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文