简体   繁体   中英

Bitmap scaling to fit different screen size/density

I do not really understand all those things about pixel density and device independant pixels and I want to know if I should worry about this.

More specifically, here is how my application work right now:

  • For the “layout screens”, I'm using RelativeLayout or LinearLayout and I never use pixels or dp, so I guess that this will look good on every device
  • For the main game screen, there is only a SurfaceView on the screen. With the values given by onSurfaceCreated() (pixels or dp? I don't know), I compute the size and position of every element of the game, then I load the Bitmaps (with BitmapFactory.decodeResource() and then Bitmap.createScaledBitmap() ) and put them on the screen with drawBitmap()

I tested on my phone (480 × 800 hdpi) and on the emulator (240 × 320 mdpi), and both looks good.

My questions are:

  • Is this the right thing to do? I do not understand how (and why) I could use the fact that some devices are hdpi and others are mdpi.
  • Should I provide different bitmaps for different screen densities, and why? (right now I have everything in res/drawable-hdpi )
  • What size should my .png have? Can I create them much bigger (2 ×) than their expected size, in order to be sure that this will not look blur or aliased?

My knowledge about this is limited, as i never developed games.. as i supposed you are doing.

Is this the right thing to do? I do not understand how (and why) I could use the fact that some devices are hdpi and others are mdpi.

With this information you can load different images automatically. You can you the directories:

drawable-hdpi drawables-mdpi ...

Should I provide different bitmaps for different screen densities, and why? (right now I have everything in res/drawable-hdpi)

If you have all in hdpi then the images will be shrinked i think, to be smaller due to the lack of specific images o that scale. Providing the images will give you more control over the final product and it will spend less processing.

What size should my .png have? Can I create them much bigger (2 ×) than their expected size, in order to be sure that this will not look blur or aliased?

I think they can be exactly the size needed. But as i said above.. not much experience.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM