項目1----------寫自己的android錄像機(2)

週六,老闆打電話讓加班,爭取到最後,在家裏苦逼的寫代碼,查資料。。。。。


我發現,MediaRecorder.setVideoSize()裏面的寬和高好像必須的是固定的值,

亂寫是不行的?why?

			mwidth = 320;
			mheight = 240;

			mwidth = 176;
			mheight = 144;
	

另外,找了網上的一個解決第2個問題的辦法:

public static void setCameraDisplayOrientation(Activity activity, int cameraId, android.hardware.Camera camera) {
		android.hardware.Camera.CameraInfo info = new android.hardware.Camera.CameraInfo();
		android.hardware.Camera.getCameraInfo(cameraId, info);
		int rotation = activity.getWindowManager().getDefaultDisplay().getRotation();
		int degrees = 0;
		switch (rotation) {
		case Surface.ROTATION_0:
			degrees = 0;
			break;
		case Surface.ROTATION_90:
			degrees = 90;
			break;
		case Surface.ROTATION_180:
			degrees = 180;
			break;
		case Surface.ROTATION_270:
			degrees = 270;
			break;
		}

		int result;
		if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
			result = (info.orientation + degrees) % 360;
			result = (360 - result) % 360; // compensate the mirror
		} else { // back-facing
			result = (info.orientation - degrees + 360) % 360;
		}
		camera.setDisplayOrientation(result);
	}

這樣錄像的時候,圖片就不拉伸了。


ps:這是週一補上的,所以忘了寫這個方法的原博文的地址了。。。囧

另外,在做的過程中,出現了“Fail to connect to camera service”的問題,

是攝像頭不能重連的問題,

這是因爲,攝像頭有的時候,沒有自動釋放。

自己釋放掉就OK了,最後在記得寫onDestroy方法,把相關的所有的處理一下,釋放掉。






發佈了76 篇原創文章 · 獲贊 3 · 訪問量 15萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章