【发布时间】:2014-04-01 05:01:44
【问题描述】:
我正在尝试加载两张图片(均为 800 x 1280),以在我的游戏中用作永久滚动的背景。我可以使用以下代码很好地加载它们:
public Image newImage(String imageName, ImageFormat format) {
Config config = null;
if (format == ImageFormat.RGB565)
config = Config.RGB_565;
else if (format == ImageFormat.ARGB4444)
config = Config.ARGB_4444;
else
config = Config.ARGB_8888;
Options options = new Options();
options.inPreferredConfig = config;
Bitmap bitmap = null;
try {
int id = resources.getIdentifier("<package>"+imageName, null, null);
bitmap = BitmapFactory.decodeResource(resources, id, options);
if (bitmap == null)
throw new RuntimeException("Couldn't load bitmap from resources");
} catch (Exception e) {
throw new RuntimeException("Failed to load image");
}
if (bitmap.getConfig() == Config.RGB_565)
format = ImageFormat.RGB565;
else if (bitmap.getConfig() == Config.ARGB_4444)
format = ImageFormat.ARGB4444;
else
format = ImageFormat.ARGB8888;
return new AndroidImage(bitmap, format);
}
但是当我在屏幕上绘制它们时,它们比实际图像要暗得多。我已确保将屏幕亮度调整为 100%,并且尝试了所有 3 种不同的图像格式。这是正在发生的事情的一个例子:
实物图
截图
【问题讨论】:
-
可能不是因为图像,而是因为你显示它的方式。视图上是否设置了一些 alpha?
-
我不相信,不过如果你愿意,我可以发布代码。
-
这个问题很老了,但我在从文件加载图像并显示它时遇到了类似的问题 - 它显示得很暗,但仅在某些手机上。我想@Henry 是对的,它与视图上的 alpha 有关,但我不知道它在哪里设置或为什么它只影响某些手机。
标签: android image brightness