Back to project page camera.
The source code is released under:
Apache License
If you think the Android project camera listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package org.yanzi.util; // ww w . j av a 2 s . c o m import android.content.Context; import android.graphics.Point; import android.util.DisplayMetrics; import android.util.Log; public class DisplayUtil { private static final String TAG = "DisplayUtil"; /** * dip?px * @param context * @param dipValue * @return */ public static int dip2px(Context context, float dipValue){ final float scale = context.getResources().getDisplayMetrics().density; return (int)(dipValue * scale + 0.5f); } /** * px?dip * @param context * @param pxValue * @return */ public static int px2dip(Context context, float pxValue){ final float scale = context.getResources().getDisplayMetrics().density; return (int)(pxValue / scale + 0.5f); } /** * ?????????????????px * @param context * @return */ public static Point getScreenMetrics(Context context){ DisplayMetrics dm =context.getResources().getDisplayMetrics(); int w_screen = dm.widthPixels; int h_screen = dm.heightPixels; Log.i(TAG, "Screen---Width = " + w_screen + " Height = " + h_screen + " densityDpi = " + dm.densityDpi); return new Point(w_screen, h_screen); } /** * ??????????? * @param context * @return */ public static float getScreenRate(Context context){ Point P = getScreenMetrics(context); float H = P.y; float W = P.x; return (H/W); } }