1

The resolution of the bitmap I'm using is 480 x 480.

When I'm trying to get the width of this bitmap inside of onSurfaceChanged using bellow code.

    public void onSurfaceChanged(SurfaceHolder holder, int format, int width, int height) {
             super.onSurfaceChanged(holder, format, width, height);

             bDialBg = BitmapFactory.decodeResource(getResources(), R.drawable.dial_bg);
             scale = ((float) width) / (float) bDialBg.getWidth();
    }

bDialBg.getWidth() result supposed to be 480 as my image is 480x480 instead the result is 720.

I double checked the image resolution I'm using, I also resized the image again using Photoshop which is 480 x 480. but still the result of bDialBg.getWidth() is 720.

esrana
  • 13
  • 3

1 Answers1

0

I faced the same issue few days ago.

Solution Put the image resource under "drawable-nodpi" instead of any other "drawable" resource directory. It solved my problem.

Explanation: The Main problem was, I was putting the image resource under "drawable" directory and it was giving me wrong width information of bitmap. Funny part was it was giving me 720 when I was using 320x320 emulator and 1080 for 480 x 480 emulator.

Hope the solution works for you.

Shekh Shagar
  • 1,305
  • 1
  • 11
  • 22