i have i .png image dans mon dossier drawable-xhdpi, ses 32x32 pixels taille:couleur bitmap Android confusion
Lorsque j'ai créé l'image i utilisé exactement deux couleurs.
lorsque je charge l'image comme une image bitmap, caniveau en boucle et imprimer chaque valeur de couleur dans le logcat je vois plus de deux valeurs de couleurs différentes:
renderSystem.addSprite(R.drawable.walltest, 0, 2);
En rendersystem:
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)));
}
}
}
Sorties:
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
Cela me dit que l'image bitmap n'a pas les mêmes couleurs comme l'image png source. Pourquoi donc? Et comment charger une réplique exacte au format bitmap?
Comment désactiver le filtrage? –
Nevermind, j'ai créé une option bitmapfactory et ai mis inscaled à true. Maintenant ça marche. –
Très bien, bon pour vous. –