Updating an Eclipse Android project via Git - image resource not updating
I am working with a team on an Android game. There was a graphics spritesheet resource that was created wit开发者_运维百科h an initial tile width of 96 pixels and later reduced to 64 pixels. On the author's computer the project runs correctly at the new dimensions but on my machine, even though the image has been updated to the new resolution, when I go into debug and call getHeight() on the BMP resource, it returns 96 and the animation displays incorrectly (gets clipped).
I have tried: refreshing eclipse filesystem re-cloning the project and creating a clean project in eclipse starting eclipse with -clean cleaning the build
The problem persists and I have run out of ideas. Please, how do I get get eclipse to uncache whatever crud its keeping somewhere and use the new image that's plainly sitting in the /res/ folder??
I am testing the project on the emulator. Running android api 2.1, level 7.
Bitmap bmp;
bmp = BitmapFactory.decodeResource(getResources(), R.drawable.blah);
You need to set the "inScaled" flag when loading the Bitmap if you want to force the original size. I found this out the hard way when my Open GL textures weren't showing up on larger screen devices.
Something like this should do it:
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inScaled = false;
Bitmap bmp = BitmapFactory.decodeResource(getResources(),
R.drawable.my_image, opts);
Android automatically scales images in the resources folder for the screen resolution of the device. So even if the source image has a height of 64 pixels, there's no guarantee the .getHeight() will return 64.
Moral of the story: don't hard-code values for the sizes of images - use the accessor methods.
精彩评论