Android Open Source - camera Display Util






From Project

Back to project page camera.

License

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.

Java Source Code

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);
  }
}




Java Source Code List

cn.bgxt.mediarecorderdemo.MainActivity.java
cn.bgxt.mediarecorderdemo.RecordActivity.java
com.example.android.photobyintent.AlbumStorageDirFactory.java
com.example.android.photobyintent.BaseAlbumDirFactory.java
com.example.android.photobyintent.FroyoAlbumDirFactory.java
com.example.android.photobyintent.PhotoIntentActivity.java
com.marcodinacci.book.acb.VideoActivity.java
org.yanzi.activity.CameraActivity.java
org.yanzi.camera.CameraInterface.java
org.yanzi.camera.preview.CameraTextureView.java
org.yanzi.util.CamParaUtil.java
org.yanzi.util.DisplayUtil.java
org.yanzi.util.FileUtil.java
org.yanzi.util.ImageUtil.java