getIntrinsicWidth() and getIntrinsicHeight() return doubled values

zehazeha Posts: 36Member
Hello,

I tried to run our game on Ouya which is written in plain Android SDK Java, and when loading the graphics, we use getIntrinsicWidth() and getIntrinsicHeight() to determine the pixel-size of that image. However, it always returns twice the amount on the Ouya. For example, if a graphic has 32x32 pixels, both functions return 64 instead of 32.

Any idea why this is the case?

Comments

  • JohnGabyJohnGaby Posts: 21Member
    edited July 2013
    I experienced this as well.  I believe that it is due to the fact the the density of the device is 320 (double the normal 160) and if you load a bitmap from a resource, Android will automatically scale the bitmap according to the device density and where the resource is located (e.g. drawable, drawable-hdpi, etc).  If your resources are all in drawable, it assumes that the density is 160 and when it loads the bitmap doubles it's size to match the 320 density of the device.  You can override this behavior by using the BitmapFactory.Options class when calling the decodeResource function and setting the 'inDensity' and 'inTargetDensity' to the same value (e.g. 160).  (You might also be able to fix it by putting your resources in the correct 'drawable' folder).
    Post edited by JohnGaby on
  • zehazeha Posts: 36Member

    okay thanks i will try that ;) i just read in the android docs that you can also use a folder called "drawable-nodpi", maybe this will do the trick :)

  • LususAnimatLususAnimat Posts: 32Member
    I can confirm that the drawable-nodpi qualifier does work. 
Sign In or Register to comment.