2012-05-31 4 views
1

나는 안드로이드 용 카메라 응용 프로그램을 만들고 있습니다. 아래 그림처럼 내 카메라 미리보기를 원합니다. 내 카메라 미리보기를 4 부분 또는 여러 부분으로 나누고 싶습니다. 어느 한 날 열심히 노력하면 사전Android 맞춤형 카메라 미리보기?

+0

네 부분으로 무엇을 원하십니까? – Shrikant

+0

내 카메라 표면에서 네 부분으로 나누어 진 미리보기를 원할 때 찍은 사진을이 효과와 함께 저장합니다. –

답변

2

덕분에이

enter image description here

어떤 예 또는 튜토리얼을 찾는 데 도움이 될 수 있습니다, 나는 해결책을 찾아 냈다. Yeaahhhh !!!

camera.xml :

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" > 

    <FrameLayout 
     android:id="@+id/preview" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 

    </FrameLayout> 
    <LinearLayout 
     android:id="@+id/imageViewLayout" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:visibility="gone" 
     android:orientation="vertical" > 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" > 

      <LinearLayout 
       android:layout_width="0dp" 
       android:layout_height="fill_parent" 
       android:layout_weight="1" > 

       <ImageView 
        android:id="@+id/img1" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:background="@drawable/ic_launcher" /> 
      </LinearLayout> 

      <LinearLayout 
       android:layout_width="0dp" 
       android:layout_height="fill_parent" 
       android:layout_weight="1" > 

       <ImageView 
        android:id="@+id/img2" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:background="@drawable/ic_launcher" /> 
      </LinearLayout> 
     </LinearLayout> 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="0dp" 
      android:layout_weight="1" > 

      <LinearLayout 
       android:layout_width="0dp" 
       android:layout_height="fill_parent" 
       android:layout_weight="1" > 

       <ImageView 
        android:id="@+id/img3" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:background="@drawable/ic_launcher" /> 
      </LinearLayout> 

      <LinearLayout 
       android:layout_width="0dp" 
       android:layout_height="fill_parent" 
       android:layout_weight="1" > 

       <ImageView 
        android:id="@+id/img4" 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:background="@drawable/ic_launcher" /> 
      </LinearLayout> 
     </LinearLayout> 
    </LinearLayout> 

    <Button 
     android:id="@+id/clickButton" 
     style="@android:style/Animation.Translucent" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentRight="true" 
     android:text="@string/click" /> 

</RelativeLayout> 

카메라 활동은 다음과 같이해야합니다 : 난 단지 당신이, 당신이 구현할 수있는 나머지 초점을 맞추어야 주요 부분이라고 생각 그 부분을 게시하고있다. 어딘가에 붙어 있다면 나 한테 물어봐. 먼저 당신이 당신의 활동에서 호출해야합니다

final Button clickButton = (Button) findViewById(R.id.clickButton); 
      clickButton.setOnClickListener(new View.OnClickListener() { 

       @Override 
       public void onClick(final View view) { 
        camera.takePicture(null, null, mPicture); 
       } 
      }); 

당신의 onPictureTaken()이 같아야합니다

/** 
    * This will be called after taking picture from camera. 
    */ 
    final transient private PictureCallback mPicture = new PictureCallback() { 
     /** 
     * After taking picture, onPictureTaken() will be called where image 
     * will be saved. 
     * 
     */ 
     @Override 
     public void onPictureTaken(final byte[] data, final Camera camera) { 
      OutputStream outStream = null; 
      try { 
       outStream = new BufferedOutputStream(new FileOutputStream(
         mGetFile)); 
       outStream.write(data); // Write the data to corresponding place. 
       ((FrameLayout) findViewById(R.id.preview)) 
         .setVisibility(View.GONE); 
       ((LinearLayout) findViewById(R.id.imageViewLayout)) 
         .setVisibility(View.VISIBLE); 
       final Options options = new Options(); 
       options.inScaled = true; 
       options.inPurgeable = true; 

       // to scale the image to 1/8 
       options.inSampleSize = 8; 

       Bitmap imageBitmap = BitmapFactory.decodeByteArray(data, 0, 
         data.length, options); 
       ImageView image1 = (ImageView) findViewById(R.id.img1); 
       ImageView image2 = (ImageView) findViewById(R.id.img2); 
       ImageView image3 = (ImageView) findViewById(R.id.img3); 
       ImageView image4 = (ImageView) findViewById(R.id.img4); 

       image1.setImageBitmap(imageBitmap); 
       image2.setImageBitmap(imageBitmap); 
       image3.setImageBitmap(imageBitmap); 
       image4.setImageBitmap(imageBitmap); 
      } catch (FileNotFoundException e) { 
       camera.release(); 
      } catch (IOException e) { 
       camera.release(); 
      } finally { 
       try { 
        outStream.close(); 

       } catch (IOException e) { 
        camera.release(); 
       } 
      } 
     } 
    }; 

이 위에서 언급 한 것과 같은 캡처 한 이미지를 표시합니다.

고맙습니다.

+0

여기에서 미리보기에 4 개 이상의 이미지가 필요하면 GridLayout을 더 잘 사용하십시오. 선형 레이아웃을 관리하는 것은 약간 복잡한 작업입니다. – Shrikant

관련 문제