天天看點

Android Camera Parameters 擷取

以下是我寫的使用Camera Parameters 擷取相機相關參數的例子,展示如何

逐個擷取所需的參數,在此記錄下,為友善自己Review,也希望能幫到其他人。

其中,picture 相關的,Preview相關的都是大家比較關心的。

(貌似對其沒弄好,不知道是Eclipse配置問題,還是這個CSDN粘貼代碼有問題,或者二者兼有?? )

Camera.Parameters parameters = mcamera.getParameters(); 
		int    CurPreFmt = parameters.getPreviewFormat();
		
		Log.d("LeoHDRTest", "Enter SurfaceChanged Function ");
		Log.d("LeoHDRTest", "PreviewFormat =" + CurPreFmt);
		switch(CurPreFmt)
		{
		case ImageFormat.JPEG:
			Log.d("LeoHDRTest", "Current Preview Format is JPEG");
			break;
		case ImageFormat.NV16:
			Log.d("LeoHDRTest", "Current Preview Format is NV16");
			break;
		case ImageFormat.NV21:
			Log.d("LeoHDRTest", "Current Preview Format is NV21");
			break;
		case ImageFormat.RGB_565:
			Log.d("LeoHDRTest", "Current Preview Format is RGB_565");
			break;
		case ImageFormat.YUY2:
			Log.d("LeoHDRTest", "Current Preview Format is YUY2");
			break;
		case ImageFormat.YV12:
			Log.d("LeoHDRTest", "Current Preview Format is YV12");
			break;	
		case ImageFormat.UNKNOWN:
			Log.d("LeoHDRTest", "Current Preview Format is UNKNOWN");
			break;	
		default:
			Log.d("LeoHDRTest", "Current Preview Format is default : UNKNOWN");
			break;				
			
		}
		
		
		Size CurpreSize = parameters.getPreviewSize(); 
        Log.d("LeoHDRTest", "current Preview Size :" + CurpreSize.width + " x " + CurpreSize.height);
        
        
        Size curPicSize = parameters.getPictureSize();
        Log.d("LeoHDRTest", "current Picture Size :" + curPicSize.width + " x " + curPicSize.height);
        
        int  CurPicFmt = parameters.getPictureFormat();
		switch(CurPicFmt)
		{
		case ImageFormat.JPEG:
			Log.d("LeoHDRTest", "Picture Format is JPEG");
			break;
		case ImageFormat.NV16:
			Log.d("LeoHDRTest", "Picture Format is NV16");
			break;
		case ImageFormat.NV21:
			Log.d("LeoHDRTest", "Picture Format is NV21");
			break;
		case ImageFormat.RGB_565:
			Log.d("LeoHDRTest", "Picture Format is RGB_565");
			break;
		case ImageFormat.YUY2:
			Log.d("LeoHDRTest", "Picture Format is YUY2");
			break;
		case ImageFormat.YV12:
			Log.d("LeoHDRTest", "Picture Format is YV12");
			break;	
		case ImageFormat.UNKNOWN:
			Log.d("LeoHDRTest", "Picture Format is UNKNOWN");
			break;	
		default:
			Log.d("LeoHDRTest", "Picture Format is default : UNKNOWN");
			break;	
			
		}
				
        int CurPreRange[];
        CurPreRange = new int[2];
        parameters.getPreviewFpsRange(CurPreRange);
        Log.d("LeoHDRTest", "Current Preview MinFps = " + CurPreRange[0]
        		+ "  MaxFps = " + CurPreRange[1]);
        
        
        Log.d("LeoHDRTest", "Current EV setting is " + 
        parameters.getExposureCompensation() * parameters.getExposureCompensationStep());
        
        Log.d("LeoHDRTest", "Jpeg Quality = " + parameters.getJpegQuality());
        
        
        Log.d("LeoHDRTest", " Min Exposure Comp  = " + parameters.getMinExposureCompensation()
        	+ "  Max Exposure Com = " + parameters.getMaxExposureCompensation());
        
		String strCurFocusMode = parameters.getFocusMode();
		if (strCurFocusMode.equalsIgnoreCase(Camera.Parameters.FOCUS_MODE_AUTO)) {
			
			Log.d("LeoHDRTest", "Current Focus Mode is FOCUS_MODE_AUTO");
			
		}else if (strCurFocusMode.equalsIgnoreCase(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) {
			
			Log.d("LeoHDRTest", "Current Focus Mode is FOCUS_MODE_CONTINUOUS_PICTURE");
		
		}else if (strCurFocusMode.equalsIgnoreCase(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO)) {
			
			Log.d("LeoHDRTest", "Current Focus Mode is FOCUS_MODE_CONTINUOUS_VIDEO");
		
		}else if (strCurFocusMode.equalsIgnoreCase(Camera.Parameters.FOCUS_MODE_INFINITY)) {
			
			Log.d("LeoHDRTest", "Current Focus Mode is FOCUS_MODE_INFINITY");
		
		}else if (strCurFocusMode.equalsIgnoreCase(Camera.Parameters.FOCUS_MODE_MACRO)) {
			
			Log.d("LeoHDRTest", "Current Focus Mode is FOCUS_MODE_MACRO");
		
		}else if (strCurFocusMode.equalsIgnoreCase(Camera.Parameters.FOCUS_MODE_FIXED)) {
			
			Log.d("LeoHDRTest", "Current Focus Mode is FOCUS_MODE_FIXED");
		
		}else if (strCurFocusMode.equalsIgnoreCase(Camera.Parameters.FOCUS_MODE_EDOF)) {
			
			Log.d("LeoHDRTest", "Current Focus Mode is FOCUS_MODE_EDOF");
		}
		
        
        List<int[]> SupPreFpsRangeList = parameters.getSupportedPreviewFpsRange();
        int SupPreRange[] = new int[2];

        Log.d("LeoHDRTest", "Support Preview FPS Range List :  " );
		for(int num = 0; num < SupPreFpsRangeList.size(); num++)
		{
			SupPreRange = SupPreFpsRangeList.get(num);	
			Log.d("LeoHDRTest", "< " + num + " >" + " Min = " + SupPreRange[0]
					+ "  Max = " + SupPreRange[1]);          
		}
		
		
		if(parameters.isAutoExposureLockSupported() )
		{
			if(parameters.getAutoExposureLock())
			{
				Log.d("LeoHDRTest", "Auto Exposure is Locked");	
			}
			else 
			{
				Log.d("LeoHDRTest", "Auto Exposure is not Locked");	
			}
		}
		
		
			
			
		List<String> focusModesList = parameters.getSupportedFocusModes();
		if (focusModesList.contains(Camera.Parameters.FOCUS_MODE_AUTO)) {
			
			Log.d("LeoHDRTest", "Camera Support AUTO FOCUS MODE");
		
		}else if (focusModesList.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) {
			
			Log.d("LeoHDRTest", "Current Focus Mode is FOCUS_MODE_CONTINUOUS_PICTURE");
		
		}else if (focusModesList.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_VIDEO)) {
			
			Log.d("LeoHDRTest", "Current Focus Mode is FOCUS_MODE_CONTINUOUS_VIDEO");
		
		}else if (focusModesList.contains(Camera.Parameters.FOCUS_MODE_INFINITY)) {
			
			Log.d("LeoHDRTest", "Current Focus Mode is FOCUS_MODE_INFINITY");
		
		}else if (focusModesList.contains(Camera.Parameters.FOCUS_MODE_MACRO)) {
			
			Log.d("LeoHDRTest", "Current Focus Mode is FOCUS_MODE_MACRO");
		
		}else if (focusModesList.contains(Camera.Parameters.FOCUS_MODE_FIXED)) {
			
			Log.d("LeoHDRTest", "Current Focus Mode is FOCUS_MODE_FIXED");
		
		}else if (focusModesList.contains(Camera.Parameters.FOCUS_MODE_EDOF)) {
			
			Log.d("LeoHDRTest", "Current Focus Mode is FOCUS_MODE_EDOF");
		}
		
		List<Integer> supPicFmtList = parameters.getSupportedPictureFormats();
		Log.d("LeoHDRTest", "Supported Picutre Format :" );
		
		for(int num = 0; num < supPicFmtList.size(); num++)
		{
		    Integer ISupPicFmt = supPicFmtList.get(num);	
		    Log.d("LeoHDRTest", "" + ISupPicFmt.intValue());
		    
		}
		
		
		List<Integer> supPreFmtList = parameters.getSupportedPreviewFormats(); 
        Log.d("LeoHDRTest", "Supported Preview Format :");
		
		for(int num = 0; num < supPreFmtList.size(); num++)
		{
		    Integer ISupPreFmt = supPreFmtList.get(num);	
		    Log.d("LeoHDRTest", "" + ISupPreFmt.intValue());
		    
		}
		
		
		List<Size> PicSupSizeList = parameters.getSupportedPictureSizes();

	    Log.d("LeoHDRTest", "Camera Supported Pic Size are :");
		for(int num = 0; num < PicSupSizeList.size(); num++)
		{
		    Size PicSupSize = PicSupSizeList.get(num);	
		    Log.d("LeoHDRTest", "< " + num +" >" + PicSupSize.width + " x " + PicSupSize.height);
		}
		
		Log.d("LeoHDRTest", "Camera Supported Preview Size are :");
		List<Size> supPreviewList = parameters.getSupportedPreviewSizes();
		for(int num = 0; num < supPreviewList.size(); num++)
		{
		    Size PicPreSupSize = supPreviewList.get(num);	
		    Log.d("LeoHDRTest", "< " + num +" >" + PicPreSupSize.width + " x " + PicPreSupSize.height);
		}