문제

내가 원하는 잠금 내 카메라 뷰 에"풍경"모드내 응용 프로그램에서 간단한 버튼을 클릭하면 그 시간 장치의 카메라가 열리고 그 카메라가 잠겨 있어야합니다 에"가로 모드".이 문제의 해결책을 아는 사람이 있습니까?

이 코드를"캡처 이미지 활동"에서 사용하고 있습니다.자바"활동.그래서이 활동을 실행 한 후 내 시스템의 카메라가 열립니다.

btn1.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            Intent i=new Intent(android.provider.MediaStore. ACTION_IMAGE_CAPTURE);
            i.putExtra(android.provider.MediaStore.EXTRA_SCREEN_ORIENTATION,ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);


            startActivityForResult(i,1000);

        }
    });

그리고 카메라 뷰를"가로 모드"로 잠그고 싶습니다.그리고 해결책에 의하여

<activity android:name=".CaptureImageActivity"
    android:screenOrientation="landscape"
              android:label="@string/app_name">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

"캡처 이미지 활동"활동 만"가로 모드"로 잠겨 있습니다.

도움이 되었습니까?

해결책

매니페스트 파일 내의 활동에 이 항목을 추가합니다

android:screenOrientation="portrait"

다른 팁

이 링크를 참조하여 카메라 방향을 잠그십시오. setDisplayOrientation (int degrees)

문서는 다음 링크에서 찾을 수 있습니다 :http://developer.android.com/reference/android/hardware/Camera.html#setDisplayOrientation%28int%29

자세한 내용은 이 답변을 참조하십시오 :

안드로이드 카메라 방향을 올바르게 설정하는 방법?

By using setCameraDisplayOrientation=
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);
 }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top