【问题标题】:Android reduce image when present in drawable folder出现在可绘制文件夹中时,Android会缩小图像
【发布时间】:2017-04-14 05:25:44
【问题描述】:

我正在画布中绘制我的游戏的 background.png 图像(图像比高宽,因为它是一个滚动的背景)。图片尺寸如下:

  • drawable-xhdpi: 1817x443 像素
  • drawable-hdpi: 1363x332 像素
  • drawable-mdpi: 909x222 像素
  • drawable-ldpi: 682x166 像素

我做了一些测试:

  1. 在我的 Oneplus X 上,图像看起来不错,但在我的三星上 Galaxy Nexus 和 Wiko Iggy 图像质量下降。
  2. 现在,如果我从 xhdpi 文件夹中删除 background.png,图像 在一加 X 和 Galaxy 上看起来不错,但在 Wiko 上仍然很差。
  3. 最后,如果我从 xhdpi 和 hdpi 文件夹中删除 background.png, 图像在所有手机上看起来都不错(好吧,一加 X 中的 xhdpi 版本 稍微好一点,但 mdpi 版本也还不错)。

2滚动背景的绘制代码:

backgroundArea.offsetTo(xBackground, backgroundArea.top);
canvas.drawBitmap(background, null, backgroundArea, mPaint);
backgroundArea.offset(backgroundArea.width(), 0);
canvas.drawBitmap(background, null, backgroundArea, mPaint);

为什么会这样?为什么它没有为正确的手机拍摄正确的图像,而是缩小了更大的可用图像?我该如何解决这个问题? (PS:我还在用Eclipse ADT)。

【问题讨论】:

  • 可能是this 的副本,并尝试更大的图像,并在加载期间根据屏幕尺寸调整其大小。
  • 请发布您的画布绘图代码。
  • @Ircover 我编辑了帖子
  • drawable 文件夹中有图片吗?我的意思是没有修饰符的文件夹。
  • @Ircover 不,在可绘制文件夹中我只有 xml 文件。但例如,我只有在 drawable-xhdpi 中有其他图像,我的意思是在 hdpi、mdpi 和 ldpi 中没有匹配的图像。也许这就是问题所在?

标签: android image android-drawable


【解决方案1】:

我的问题是 Oneplus X 有 xxhdpi 分辨率,三星 Galaxy xhdpi 和 Wiko Iggy hdpi (You can use this app to discover the resolution)。 所以我创建了一个新文件夹 drawable-xxhdpi 并将所有 background.png 移动到“楼上一层”(我把我的 1817x443 图像从 xhdpi 到 xxhdpi 等等)。你可以使用这个比例:

LDPI - 0.75x
MDPI - Original size // means 1.0x here 
HDPI - 1.5x
XHDPI - 2.0x
XXHDPI - 3x
XXXHDPI - 4.0x

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-12-14
    • 1970-01-01
    • 1970-01-01
    • 2012-05-31
    • 1970-01-01
    • 2016-11-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多