Android: How to stop Android 1.6+ from scaling images

こ雲淡風輕ζ 提交于 2019-11-30 16:17:11

问题


I updated my build to build against Android 1.6, and now my bitmaps are scaled down on high density screens. I do NOT want this behavior. I gave this a shot:

http://blog.tomgibara.com/post/190539066/android-unscaled-bitmaps

but the images are STILL scaling, that is UNLESS I set them to a specific height & width. If I use wrap_content they are scaled down.

I have an image loader using the unscaled bitmap loader to create a drawable like so:

Bitmap bm = UnscaledBitmapLoader.loadFromResource(imageBufferInputStream);
drawable = new BitmapDrawable(bm);

which I later assign to an ImageView like so:

imageView.setImageDrawable( copyBitmapDrawable( (BitmapDrawable) drawable) );

回答1:


In order to have an image not scaled when loading it from a resource (e.g. with BitmapFactory.decodeResource) you have to locate it in res/drawable-nodpi instead of the usual drawable, drawable-ldpi and so on.




回答2:


Using

new BitmapDrawable(this.getResources(), bmp); 

instead of

 new BitmapDrawable(bmp);

should solve the issue.




回答3:


Wrapping the bitmap with a Drawable is the problem. The Drawable scales the Bitmap. Instead of using a Drawable, assign the Bitmap to the ImageView directly using imageView.setImageBitmap(Bitmap).




回答4:


Use ImageView.ScaleType. The CENTER constant preforms no scaling, so I guess that's what you are looking for.

By the way, do you use pixels or dips as size units? Using dips (density-independent-pixels) is a means of standardizing display on multiple resolutions. You'll find a couple of tips here.



来源:https://stackoverflow.com/questions/4091921/android-how-to-stop-android-1-6-from-scaling-images

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