Tuesday, 15 November 2016

BitmapFactory gives me larger image than my real image


My code is:

I am loading a image from resource folder:

Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.image)

Log.d("xxx", "h: " + bitmap.getHeight() + " w: " + bitmap.getWidth());

But the image is larger than my real image.


Solution:


The screen density on the android device has different density of my PC.

to keep the density/scaling, you have 2 options:

1. Put the image in res/drawable-nodpi (http://developer.android.com/guide/practices/screens_support.html#qualifiers)

2. Use ImageView.ScaleType.CENTER (http://developer.android.com/reference/android/widget/ImageView.ScaleType.html)

For drawing onto a imageView:

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



http://stackoverflow.com/questions/7363643/bitmapfactory-returns-bigger-image-than-source

No comments:

Post a comment