Android Open Source - camera Cam Para 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;
//from ww w  . j a  va  2s.c  o m
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import android.hardware.Camera;
import android.hardware.Camera.Size;
import android.util.Log;

public class CamParaUtil {
  private static final String TAG = "yanzi";
  private CameraSizeComparator sizeComparator = new CameraSizeComparator();
  private static CamParaUtil myCamPara = null;
  private CamParaUtil(){

  }
  public static CamParaUtil getInstance(){
    if(myCamPara == null){
      myCamPara = new CamParaUtil();
      return myCamPara;
    }
    else{
      return myCamPara;
    }
  }

  public  Size getPropPreviewSize(List<Camera.Size> list, float th, int minWidth){
    Collections.sort(list, sizeComparator);

    int i = 0;
    for(Size s:list){
      if((s.width >= minWidth) && equalRate(s, th)){
        Log.i(TAG, "PreviewSize:w = " + s.width + "h = " + s.height);
        break;
      }
      i++;
    }
    if(i == list.size()){
      i = 0;//????????????????size
    }
    return list.get(i);
  }
  public Size getPropPictureSize(List<Camera.Size> list, float th, int minWidth){
    Collections.sort(list, sizeComparator);

    int i = 0;
    for(Size s:list){
      if((s.width >= minWidth) && equalRate(s, th)){
        Log.i(TAG, "PictureSize : w = " + s.width + "h = " + s.height);
        break;
      }
      i++;
    }
    if(i == list.size()){
      i = 0;//????????????????size
    }
    return list.get(i);
  }

  public boolean equalRate(Size s, float rate){
    float r = (float)(s.width)/(float)(s.height);
    if(Math.abs(r - rate) <= 0.03)
    {
      return true;
    }
    else{
      return false;
    }
  }

  public  class CameraSizeComparator implements Comparator<Camera.Size>{
    public int compare(Size lhs, Size rhs) {
      // TODO Auto-generated method stub
      if(lhs.width == rhs.width){
        return 0;
      }
      else if(lhs.width > rhs.width){
        return 1;
      }
      else{
        return -1;
      }
    }

  }

  /**???????previewSizes
   * @param params
   */
  public  void printSupportPreviewSize(Camera.Parameters params){
    List<Size> previewSizes = params.getSupportedPreviewSizes();
    for(int i=0; i< previewSizes.size(); i++){
      Size size = previewSizes.get(i);
      Log.i(TAG, "previewSizes:width = "+size.width+" height = "+size.height);
    }
  
  }

  /**???????pictureSizes
   * @param params
   */
  public  void printSupportPictureSize(Camera.Parameters params){
    List<Size> pictureSizes = params.getSupportedPictureSizes();
    for(int i=0; i< pictureSizes.size(); i++){
      Size size = pictureSizes.get(i);
      Log.i(TAG, "pictureSizes:width = "+ size.width
          +" height = " + size.height);
    }
  }
  /**???????????
   * @param params
   */
  public void printSupportFocusMode(Camera.Parameters params){
    List<String> focusModes = params.getSupportedFocusModes();
    for(String mode : focusModes){
      Log.i(TAG, "focusModes--" + mode);
    }
  }
}




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