2012-02-07 6 views
0

나는이 튜토리얼을 따라 사용자 정의 카메라 응용 프로그램을 쓰고 있어요 : http://marakana.com/forums/android/examples/39.html안드로이드 사용자 정의 카메라 결과 이미지 방향

지금 내가 카메라를 사용하고 사용자 후 이미지 데이터가 버튼을 클릭 얻을 수 있어요. 하지만 내가 미리보기가 괜찮다고 surfaceCreated

@Override 
public void surfaceCreated(SurfaceHolder holder) { 
    // Open the camera when the preview is created 
    Log.d("Callback", "[surfaceCreated]"); 
    theCamera = Camera.open(); 

    Display display = ((WindowManager)getSystemService(WINDOW_SERVICE)).getDefaultDisplay(); 
    int displayRotation = display.getRotation(); 
    switch (displayRotation) { 
     case Surface.ROTATION_0:  theCamera.setDisplayOrientation(90); break; 
     case Surface.ROTATION_90:  break; 
     case Surface.ROTATION_180:  break; 
     case Surface.ROTATION_270:  theCamera.setDisplayOrientation(180); break; 
    } 
} 

에 다음 코드를 추가 할 수 있도록 미리보기가 측방으로되는 문제가있어. 그러나 이미지 데이터를 얻었을 때 을 사용하여 비트 맵을 가져 와서 내 xml 레이아웃에 정의 된 my imageView로 설정합니다. 여기

<SurfaceView 
    android:id="@+id/previewSurfaceView" 
    android:layout_width="100dp" 
    android:layout_height="100dp" 
    android:layout_gravity="center" /> 

<LinearLayout 
    android:id="@+id/linearLayout1" 
    android:layout_width="fill_parent" 
    android:layout_height="250px" > 

    <Button 
     android:id="@+id/button1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_vertical" 
     android:text="Button" /> 

    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="100dp" 
     android:layout_height="100dp" 
     android:layout_gravity="center_vertical" 
     android:layout_weight="1" 
     android:maxHeight="100dp" 
     android:maxWidth="100dp" 
     android:scaleType="fitCenter" 
     android:src="@drawable/ic_launcher" /> 

</LinearLayout> 

<LinearLayout 
    android:id="@+id/linearLayout2" 
    android:layout_width="fill_parent" 
    android:layout_height="250px" > 

    <Button 
     android:id="@+id/button2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center_vertical" 
     android:text="Button" /> 

    <ImageView 
     android:id="@+id/imageView2" 
     android:layout_width="100dp" 
     android:layout_height="100dp" 
     android:layout_gravity="center_vertical" 
     android:layout_weight="1" 
     android:maxHeight="100dp" 
     android:maxWidth="100dp" 
     android:scaleType="fitCenter" 
     android:src="@drawable/ic_launcher" /> 

</LinearLayout> 

previewSurfaceView 내가 클릭했을 때 카메라 미리보기

을 button1과 button2를위한 버튼이라는 작은 뷰 내 main.xml에있다 , 카메라는 이미지를 캡처하고 imageView1/imageView2에 해당하는 이미지 데이터를 설정합니다.

몇 가지 문제가 있습니다

  1. 나는 fitCenter에, 100dp도 스케일 유형을 레이아웃 폭과 높이도 최대 폭과 높이를 설정합니다. 그러나 그것은 내가 원하는 것을 보여주지 않는 것 같습니다. 이미지가 바운드 내부에 표시되기를 원합니다. 레이아웃 설정에서 잘못하고 있습니까? 이미지가 풍경에 항상

  2. 는 심지어 세로 모드에서 사진을 찍었.

게다가, 나는 카메라의 오프/온을 전환 할 수있는 버튼을 추가 할 수 있지만이 작업을 수행하는 방법을 알아낼 수 없습니다.

은 누군가가 나를 위해 솔루션을 제안 할 수 있습니다? 고맙습니다.

답변

0

내 대답 here을 보니 동일한 문제가있는 것으로 보입니다.

+0

죄송합니다. 위의 잘못된 코드를 게시했습니다. 나는 표면보기에 아무런 문제가 없다. 그러나 이미지 데이터의 방향을 어떻게 얻을 수 있습니까? 그것은 데이터에서 EXIF를 얻을 수없는 것 같습니다 – Hanon

0

카메라 매개 변수 개체에서 setRotation 메서드를 호출 한 다음 카메라에서 매개 변수를 설정해야합니다.

는 회전이 setRotation

샘플 코드 사용 here에 그 값을 사용하여 얻을 수있는 OrientationListener를 구현합니다.

+0

나는 0, 90, 180 및 270 하드 코드로 그것을 시도했다. 그러나 이미지 데이터는 여전히 풍경에 항상있다. 이미지가 항상 세로 모드로 찍히고 세로 모드로 표시되기를 원합니다. – Hanon

+0

장치를 potrait 모드로 유지하고 회전을 90으로 설정하면 세로 모드로 사진을 가져와야합니다. – bluefalcon

관련 문제