I don't want Android to resize my bitmap Automatically

徘徊边缘 提交于 2019-12-17 16:47:07

问题


I have placed some bitmaps in res/drawable.

After I load the bitmaps by BitmapFactory.decodeResource(), I find out that they are resized automatically according the density.

This is not what I want. I want them to keep their original size (pixel size).

What should I do?


回答1:


As was said in another question, using the drawable-nodpi folder will prevent android from resizing your pictures.

Additionally, if you want to have multiple versions of an image for hdpi and ldpi format, but don't want the system to resize them (to keep a power of two resolution for example), you can use the following code while loading your bitmpap :

// ask the bitmap factory not to scale the loaded bitmaps
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inScaled = false;

// load the bitmap
Bitmap bitmap = BitmapFactory.decodeResource(ctx.getResources(), R.id.mybmp, opts);



回答2:


http://developer.android.com/guide/practices/screens_support.html

If you use the nodpi suffix, the system won't scale your pictures automatic. Hope it helps!




回答3:


If you have kept separate images in your hdpi, ldpi, and mdpi, and you are using resources to access these images, then you can't do much.

If you just want one image to be used, keep a single copy of it in mdpi folder, and delete the others.




回答4:


Place your images in a folder called "drawable" (without the ldpi, mdpi, hdpi et. al. suffix). You may probably need to create it by yourself (Eclipse for example, doesn't create this automatically).

After that, delete the drawable resource from your other drawable-something folders.



来源:https://stackoverflow.com/questions/6805355/i-dont-want-android-to-resize-my-bitmap-automatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!