2013-04-15 5 views
2

카메라의 참조를 얻으려면 (거꾸로) 미러링, 내가 이렇게 :넥서스 7 카메라 (? 또는 모든 전면 카메라)

setCameraDisplayOrientation이 (나는 어딘가에 유래에서 발견되는)이다
@Override 
    public void surfaceCreated(SurfaceHolder holder) { 
     Log.d(TAG, "Surface created!"); 
     mCamera = Camera.open(); 
     if (mCamera == null) { 
      // try to open front facing camera 
      try { 
       mCamera = Camera.open(0); 
      } catch (RuntimeException e) { 
       Toast.makeText(getApplicationContext(), 
         "No camera available!", Toast.LENGTH_LONG).show(); 
      } 
     } 
     try { 
      mCamera.setPreviewDisplay(mCameraHolder); 
      setCameraDisplayOrientation(CameraActivity.this, 0, mCamera); 
     } catch (Exception e) { 
      e.printStackTrace(); 
      if (mCamera != null) 
       mCamera.release(); 
      mCamera = null; 
     } 
    } 

:

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

Nexus 4로 사진을 찍을 때 올바른 방향입니다. 앞면 카메라 만있는 Nexus 7을 사용해 보았을 때 거울면이 거꾸로되어 있습니다. (실제로이 코드 조각이 없기 때문에 추측 할 수 없습니다.).

카메라 방향을 잡고이 작업을 수행 할 수있는 확실한 방법이 있습니까? Google 및 Stackoverflow에서 검색했지만 지금까지 작동하는 항목을 찾지 못했습니다.

+0

나는 정상적인 (그리고 예상되는 행동) 비디오 채팅을위한 모든 "웹캠"이 이것을 할 것이라고 확신한다. 미러링되지 않은 경우 화면 왼쪽으로 이동하면 이미지가 화면 오른쪽으로 이동하게되고 사용자가 다소 방향을 잃게됩니다. 이미지가 거울없이 저장됩니까? – 323go

+0

좋아, 지금 수직으로 올바른지 여부를 모르겠습니다. 그래서 나는 내 얼굴 사진을 찍을 때 거꾸로되어있다. – damian

+0

흠, 괜찮아. 맞지 않아. 넥시 4, 7, 10 및 몇 개의 삼성 탭이 있습니다. 오늘 오후에 시간이 있으면 확인해 볼게. – 323go

답변

1

이것은 넥서스 7 및 HTC One M8, Lenovo Yoga, Lg G4 Nexus 4, Note 4 및 Oneplus One과 같이 테스트 한 대다수 다른 장치에서 작동하는 것으로 나타났습니다.

카메라 .setDisplayOrientation (90);

하지만이 솔루션은 미리보기를 뒤집는 Nexus 6에서는 작동하지 않으므로 다른 사람보다 더 나은 해결책이 있다면 공유하시기 바랍니다.

관련 문제