How to get X & Y resolution in DPI for the android platform?
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 开发者_JS百科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.
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.
精彩评论