0

I'm drawing in a Canvas a background.png image of my game (the image is wider than high because is a scolling background). The images have this sizes:

  • drawable-xhdpi: 1817x443 px
  • drawable-hdpi: 1363x332 px
  • drawable-mdpi: 909x222 px
  • drawable-ldpi: 682x166 px

I did some testing:

  1. On my Oneplus X the image looks pretty good, but on my Samsung Galaxy Nexus and Wiko Iggy the image lose quality.
  2. Now, if I remove the background.png from xhdpi folder, the image looks good on Oneplus X and Galaxy, but it is still bad on Wiko.
  3. At the end, if I remove the background.png from both xhdpi and hdpi folder, the image looks good in all mobiles (Ok, the xhdpi version in Oneplus X was a little better, but the mdpi version is still good too).

The drawing code of the 2 scrolling background:

backgroundArea.offsetTo(xBackground, backgroundArea.top);
canvas.drawBitmap(background, null, backgroundArea, mPaint);
backgroundArea.offset(backgroundArea.width(), 0);
canvas.drawBitmap(background, null, backgroundArea, mPaint);

Why are this happening? Why does It not taking the right image for the right mobile and instead it shrinks the bigger available image? How I can solve this? (PS: I'm still using Eclipse ADT).

Accollativo
  • 1,537
  • 4
  • 32
  • 56
  • Probably duplicate of [this](http://stackoverflow.com/questions/4837715/how-to-resize-a-bitmap-in-android), and try larger image and during load, resize it as per screen size. – ADM Apr 12 '17 at 10:58
  • Please post your canvas drawing code. – Ircover Apr 12 '17 at 11:00
  • @Ircover I edited the post – Accollativo Apr 12 '17 at 11:07
  • Do you have any images in `drawable` folder? I mean folder without modificators. – Ircover Apr 12 '17 at 13:29
  • @Ircover No, in the drawable folder I have just xml files. But for example I have other images in the drawable-xhdpi only, I mean images that don't have a match in hdpi, mdpi and ldpi. Maybe is this the problem? – Accollativo Apr 12 '17 at 19:26

1 Answers1

0

My problem was that Oneplus X has xxhdpi resolution, the Samsung Galaxy xhdpi and Wiko Iggy hdpi (You can use this app to discover the resolution). So I created a new folder drawable-xxhdpi and moved all background.png "one floor upstair" (I put my 1817x443 image from xhdpi to xxhdpi and so on). You can use this scale:

LDPI - 0.75x
MDPI - Original size // means 1.0x here 
HDPI - 1.5x
XHDPI - 2.0x
XXHDPI - 3x
XXXHDPI - 4.0x
Accollativo
  • 1,537
  • 4
  • 32
  • 56