views:

44

answers:

1

How do I obtain the X & Y resolution of a Bitmap in DPI on the android platform? I'm expecting some api like 'GetXResInDPI()' like below :

double getXResolution(Bitmap bmp) { double lXRes = Bmp.GetXResInDPI(); return lXRes; }

I'm unable to obtain any such method for the android platform in spite of scourging through the java doc.

Any help would be appreciated.

A: 

I'm not sure I understand the question, but it looks like you might be looking for getScaledHeight() / getScaledWidth().

int xdpi, ydpi;
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
Bitmap bmp = BitmapFactory.decodeResources(getResources(), R.drawable.my_bitmap);
xdpi = bmp.getScaledWidth(metrics);
ydpi = bmp.getScaledHeight(metrics);

Again, I may be misunderstanding your question, but that sounds like what you're looking for.

kcoppock
Roy Samuel
Is there a reason you can't use Bitmap.getWidth() and Bitmap.getHeight()?
kcoppock