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.


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:



No comments:

Post a comment