티스토리 뷰

Android Manifest 선언

카메라 클래스는 이미지 캡쳐 세팅, 미리보기 시작/종료, 스탭 픽쳐를 세팅하기 위해 사용하거나 비디오 인코딩을 위해 프레임을 가져오기 위해 사용한다. 이 클래스는 실제 카메라 하드웨어를 관리하는 Camera service 의 클리이언트다.

The Camera class is used to set image capture settings, start/stop preview, snap pictures, and retrieve frames for encoding for video. This class is a client for the Camera service, which manages the actual camera hardware.

디바이스 카메라에 접근하려면, 반드시 Android Manifest 에 CAMERA permission 을 선언해야 한다. 또한 <uses-feature> manifest element 를 포함해서 어플리케이션에서 사용하려는 카메라의 특징등을 포함하도록 한다.

To access the device camera, you must declare the CAMERA permission in your Android Manifest. Also be sure to include the <uses-feature> manifest element to declare camera features used by your application. For example, if you use the camera and auto-focus feature, your Manifest should include the following:

 <uses-permission android:name="android.permission.CAMERA" />
 
<uses-feature android:name="android.hardware.camera" />
 
<uses-feature android:name="android.hardware.camera.autofocus" />

클래스를 사용해서 사진찍는 방법

  1. open(int) 으로 카메라 인스턴스 획득
  2. getParameters() 로 기본적인 세팅값 얻기
  3. 필요하다면 회수한 Camera.Parameters 객체를 수정하고 setParameters(Camera.Parameters) 호출하기
  4. 원한다면 setDisplayOrientation(int) 사용
  5. 중요: 전체 초기화된 SurfaceHolder 를 setPreviewDisplay(SurfaceHolder) 로 넘기기. surface 없이, 카메라는 프리뷰를 시작할 수 없다.
  6. 중요: startPreview() 를 호출해서 preview surface 업데이트를 시작한다. 미리보기는 반드시 사진을 찍기전에 시작해야 한다.
  7. 원한다면, takePicture(Camera.ShutterCallback, Camera.PictureCallback, Camera.PictureCallback, Camera.PictureCallback)를 호출해서 사진을 캡쳐한다. 실제 이미지 데이타가 제공하는 콜백을 기다린다.
  8. 사진을 찍은 후, 미리보기는 중지된 것이다. 다른 사진을 찍기 원한다면 startPreview() 를 다시 시작한다.
  9. 중요 : release() 를 호출해서 다른 애플리케이션이 사용할 수 있게 카메라를 풀어준다. 애플리케이션은 onPause() 에서 즉시 카메라를 해지시키고 onResume()에서 재시작 한다.

  1. Obtain an instance of Camera from open(int).
  2. Get existing (default) settings with getParameters().
  3. If necessary, modify the returned Camera.Parameters object and call setParameters(Camera.Parameters).
  4. If desired, call setDisplayOrientation(int).
  5. Important: Pass a fully initialized SurfaceHolder to setPreviewDisplay(SurfaceHolder). Without a surface, the camera will be unable to start the preview.
  6. Important: Call startPreview() to start updating the preview surface. Preview must be started before you can take a picture.
  7. When you want, call takePicture(Camera.ShutterCallback, Camera.PictureCallback, Camera.PictureCallback, Camera.PictureCallback) to capture a photo. Wait for the callbacks to provide the actual image data.
  8. After taking a picture, preview display will have stopped. To take more photos, call startPreview() again first.
  9. Call stopPreview() to stop updating the preview surface.
  10. Important: Call release() to release the camera for use by other applications. Applications should release the camera immediately in onPause() (and re-open() it in onResume()).

신속한 비디오 녹화 모드로의 전환

  1. Camera 를 획득하고 처기화한다음 위에서 설명한것처럼 미리보기를 시작한다.
  2. unlock() 를 호출해서 media process가 카메라에 접근할 수 있도록 한다.
  3. 카메라를 setCamera(Camera)로 넘겨준다. 비디오 녹화에 관한 정보는 MediaRecorder를 참조해라
  4. 녹화가 끝나면 reconnect()를 호출해서 카메라를 다시 획득하고 잠근다.
  5. 원한다면 미리보기를 시작하고, 다른 사진이나 비디오를 찍는다.
  6. 위에서 설명한 것처럼 stopPreview()와 release()를 호출한다.

  1. Obtain and initialize a Camera and start preview as described above.
  2. Call unlock() to allow the media process to access the camera.
  3. Pass the camera to setCamera(Camera). See MediaRecorder information about video recording.
  4. When finished recording, call reconnect() to re-acquire and re-lock the camera.
  5. If desired, restart preview and take more photos or videos.
  6. Call stopPreview() and release() as described above.
댓글