【发布时间】:2017-09-19 21:15:01
【问题描述】:
我的 drawable-xhdpi 文件夹中有我的 png-image,其大小为 32x32 像素:
当我将图像加载为位图时,循环遍历它并在 logcat 中打印每个颜色值,我会看到两个以上不同的颜色值:
renderSystem.addSprite(R.drawable.walltest, 0, 2);
在渲染系统中:
public void addSprite(int id, int x, int y) {
Bitmap image = BitmapFactory.decodeResource(context.getResources(), id);
printColors(image);
//active.add(new Sprite(image, worldToScreenX(x), worldToScreenY(y)));
}
private void printColors(Bitmap src) {
for (int i = 0; i < src.getWidth(); i++) {
for (int j = 0; j < src.getHeight(); j ++) {
Log.d("Color", String.valueOf(src.getPixel(i,j)));
}
}
}
输出:
09-19 13:03:38.832 2576-2576/com.example.benjamin.dungeondweller I/chatty: uid=10082(u0_a82) com.example.benjamin.dungeondweller identical 36 lines
09-19 13:03:38.832 2576-2576/com.example.benjamin.dungeondweller D/Color: -7975603
09-19 13:03:38.832 2576-2576/com.example.benjamin.dungeondweller D/Color: -10734540
09-19 13:03:38.832 2576-2576/com.example.benjamin.dungeondweller D/Color: -16777216
09-19 13:03:38.832 2576-2576/com.example.benjamin.dungeondweller D/Color: -16777216
09-19 13:03:38.832 2576-2576/com.example.benjamin.dungeondweller D/Color: -11325392
09-19 13:03:38.832 2576-2576/com.example.benjamin.dungeondweller D/Color: -7975603
09-19 13:03:38.832 2576-2576/com.example.benjamin.dungeondweller I/chatty: uid=10082(u0_a82) com.example.benjamin.dungeondweller identical 8 lines
09-19 13:03:38.832 2576-2576/com.example.benjamin.dungeondweller D/Color: -7975603
09-19 13:03:38.851 2576-2576/com.example.benjamin.dungeondweller D/Color: -10734540
09-19 13:03:38.857 2576-2576/com.example.benjamin.dungeondweller I/chatty: uid=10082(u0_a82) com.example.benjamin.dungeondweller identical 9 lines
09-19 13:03:38.857 2576-2576/com.example.benjamin.dungeondweller D/Color: -10734540
09-19 13:03:38.857 2576-2576/com.example.benjamin.dungeondweller D/Color: -12639196
09-19 13:03:38.857 2576-2576/com.example.benjamin.dungeondweller D/Color: -16777216
09-19 13:03:38.860 2576-2576/com.example.benjamin.dungeondweller I/chatty: uid=10082(u0_a82) com.example.benjamin.dungeondweller identical 41 lines
09-19 13:03:38.860 2576-2576/com.example.benjamin.dungeondweller D/Color: -16777216
这告诉我位图图像与源 png 图像的颜色不同。这是为什么?以及如何加载位图格式的精确副本?
【问题讨论】: