问题
I'm trying to create a map for a game through an image, where each black pixel is equivalent to a wall, and yellow to flowers(1) and green grass(0) so far i had this image (50x50): http://i.imgur.com/Ydj9Cp2.png
the problem here seems to be that, when i read the image on my code, it get's scaled up to 100x100, even tough i have it on the raw folder. I can't let it scale up or down because that will put noise and blur on the image and then the map won't be readable.
here i have my code:
(...)
Bitmap tab=BitmapFactory.decodeResource(resources, com.example.lolitos2.R.raw.mappixel);
//tab=Bitmap.createScaledBitmap(tab, 50, 50, false);
Log.e("w", tab.getWidth()+"."+tab.getHeight());
for (int i = 0; i < tab.getWidth(); i++) {
for (int j = 0; j < tab.getHeight(); j++) {
int x = j;
int y = i;
switch (tab.getPixel(x, y)) {
// se o é uma parede
case Color.BLACK:
getParedes()[x][y] = new Parede(x, y);
break;
case Color.GREEN:
fundo.add(new Passivo(x,y,0));
break;
default:
fundo.add(new Passivo(x,y,1));
}
}
}
How can i read my image Map without rescaling it?
回答1:
Put them in the drawable-nodpi
folder, instead of in raw
, then just read them as any other BitmapDrawable
.
If you have some drawable resources that the system should never scale (perhaps because you perform some adjustments to the image yourself at runtime), you should place them in a directory with the nodpi configuration qualifier. Resources with this qualifier are considered density-agnostic and the system will not scale them.
(From http://developer.android.com/guide/practices/screens_support.html)
(If necessary, there are other ways, e.g. you can provide an inDensity
parameter to the options of BitmapFactory.decodeResource
).
回答2:
Problem is at following line
tab=Bitmap.createScaledBitmap(tab, 50, 50, false);
Change those 50s to larger number.
Hit like if I helped you Thanks
来源:https://stackoverflow.com/questions/24006461/load-image-without-autoscaling-in-android