tags:

views:

429

answers:

2

I have a view that I am drawing to a bitmap, saving to disk and then putting in an ImageView via setImageURI. However, when the image is displayed in the ImageView it is not being shown at the correct size. It is about 1/3 smaller than it should be. I'm guessing that this is a density issue, but I can't figure out what's going wrong (my emulator is WVGA). Ideas anyone?

A: 

You're right This is a density issue. To ensure that your image displays in the correct dimensions regardless of the density of the device you should consider using dip (density independent pixel) units.

Also, Android 1.5 does not support image density -- ie. it doesn't know how to distinguish between mdpi, hdpi, ldpi bitmaps. Android 1.6 and above does. You can use Bitmap.setDensity() or BitmapDrawable.setTargetDensity()

Finally -- you mention it is 1/3 small that it should be which is a good indication that the problem is related to density as mdpi density is 160dpi and hdpi is 240dpi -- 160/240 = 2/3 which is 1/3 less than your original image.

Hope this helps!

jagsaund
Thanks jagsaund. The problem is that I'm trying to load the image into an ImageView using setImageURI and I don't see a way to set the density of the ImageView.
herbrandson
A: 

Try this:

ImageView photo = (ImageView)findViewById(R.id.photo);
photo.setScaleType(ImageView.ScaleType.CENTER);
jBilbo