禁用Android资源/图片/PNG优化 [英] Disable Android resource / image / PNG optimization

查看:39
本文介绍了禁用Android资源/图片/PNG优化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何防止 Android构建过程"优化 .png 图像?

我有一个包含以下 res 目录的 Android 项目:

-/res/-/res/drawable-/res/drawable-hdpi-/res/drawable-hdpi-v5-/res/drawable-ldpi-/res/drawable-ldpi-v5-/res/drawable-mdpi-/res/drawable-mdpi-v5

这些目录包含许多 .png 文件.我用PNGOUTWin优化了PNG尺寸,整体尺寸缩小了20%以上.当我构建 .apk 文件时,图像被构建过程优化",整体大小现在比初始大小高 10%,或比我的/PNGOUTWin 优化大小高 30%.>

我的目标是减小 .apk 大小,即使它会影响最终性能、内存要求等.如何防止构建过程"优化 .png 图像?

我的目标是 Android 2.2 及更高版本.

P.S.:我目前正在从 Eclipse 构建我的 Android 项目,但稍后我将切换到自动构建(Ant?).

关于 JPG 图片的注意事项:JPG 无法使用,因为它们没有透明度.

解决方案

Android 文档中提到:http://developer.android.com/guide/topics/graphics/2d-graphics.html#drawables

<块引用>

注意:放置在 res/drawable/中的图片资源可能会被 aapt 工具自动优化无损图片压缩构建过程.例如,不需要的真彩色 PNG可以将超过 256 种颜色转换为带有颜色的 8 位 PNG调色板.这将导致图像质量相同,但需要更少的内存.所以请注意,图像二进制文件放置在这个目录可以在构建过程中改变.

因此,如果您想减小应用程序的大小,您应该减少 PNG 文件的颜色深度(这很有帮助)或尽可能切换到 .JPG 文件.>

How do I prevent the Android "build process" from optimizing .png images?

I have an Android project with the following res directories:

- /res/
- /res/drawable
- /res/drawable-hdpi
- /res/drawable-hdpi-v5
- /res/drawable-ldpi
- /res/drawable-ldpi-v5
- /res/drawable-mdpi
- /res/drawable-mdpi-v5

These directories contain many .png files. I optimize PNG sizes with PNGOUTWin, and the overall size is reduced by more than 20%. When I build the .apk file, the images are "optimized" by the build process and the overall size is now 10% above the initial size, or 30% above my/PNGOUTWin optimized size.

My goal is to reduce the .apk size, even if it will affect the final performance, memory requirements, etc. How do I prevent the "build process" from optimizing .png images?

I'm targeting Android 2.2 and above.

P.S.: I am currently building my Android project from Eclipse, but I will switch to the automated build later (Ant?).

Note about JPG images: JPG will not work, because they do not have transparency.

解决方案

As mentioned in the Android documentation: http://developer.android.com/guide/topics/graphics/2d-graphics.html#drawables

Note: Image resources placed in res/drawable/ may be automatically optimized with lossless image compression by the aapt tool during the build process. For example, a true-color PNG that does not require more than 256 colors may be converted to an 8-bit PNG with a color palette. This will result in an image of equal quality but which requires less memory. So be aware that the image binaries placed in this directory can change during the build.

So if you want to reduce the size of your application you should either reduce the color-depth of your PNG files (this helps a lot) or switch to .JPG files wherever possible.

这篇关于禁用Android资源/图片/PNG优化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆