Android.hardware.Camera
안드로이드 카메라에 대한 설명.
To take pictures with this class, use the following steps
- Obtain an instance of Camera from open(int).
- Get existing (default) settings with getParameters().
- If necessary, modify the returned Camera.Parameters object and call setParameters(Camera.Parameters).
- If desired, call setDisplayOrientation(int).
- Important: Pass a fully initialized SurfaceHolder to setPreviewDisplay(SurfaceHolder). Without a surface, the camera will be unable to start the preview.
- Important: Call startPreview() to start updating the preview surface. Preview must be started before you can take a picture.
- 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.
- After taking a picture, preview display will have stopped. To take more photos, call startPreview() again first.
- Call stopPreview() to stop updating the preview surface.
- 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()).
To quickly switch to video recording mode, use these steps
- Obtain and initialize a Camera and start preview as described above.
- Call unlock() to allow the media process to access the camera.
- Pass the camera to setCamera(Camera). See MediaRecorder information about video recording.
- When finished recording, call reconnect() to re-acquire and re-lock the camera.
- If desired, restart preview and take more photos or videos.
- Call stopPreview() and release() as described above.
Capture camera preview and GLSurfaceView to a file
카메라 제어에서 콜백함수로 Bitmap 이 안들어 올때
static public void decodeYUV420SP(int[] rgb, byte[] yuv420sp, int width, int height) {
final int frameSize = width * height;
for (int j = 0, yp = 0; j < height; j++) {
int uvp = frameSize + (j >> 1) * width, u = 0, v = 0;
for (int i = 0; i < width; i++, yp++) {
int y = (0xff & ((int) yuv420sp[yp])) - 16;
if (y < 0)
y = 0;
if ((i & 1) == 0) {
v = (0xff & yuv420sp[uvp++]) - 128;
u = (0xff & yuv420sp[uvp++]) - 128;
}
int y1192 = 1192 * y;
int r = (y1192 + 1634 * v);
int g = (y1192 - 833 * v - 400 * u);
int b = (y1192 + 2066 * u);
if (r < 0) r = 0; else if (r > 262143) r = 262143;
if (g < 0) g = 0; else if (g > 262143) g = 262143;
if (b < 0) b = 0; else if (b > 262143) b = 262143;
rgb[yp] = 0xff000000 | ((r << 6) & 0xff0000) | ((g >> 2) & 0xff00) | ((b >> 10) & 0xff);
}
}
}
// The int[] rgb buffer passed in should be at least width * height in length.
Android 카메라에서 Surface로 사진찍고 저장 및 불러올 때 화면 돌아가있다면?
일반 안드로이드에 내장된 프로그램으로 Intent 호출하여 찍는다면 orientation 정보가 추가되어있어 그것만 보고 돌리면 된다만 surface로 직접 만들어 찍으면 정보가 없다. 그럴땐 저장할 때 돌려주자 아래 처럼 2.2 이상에서 잘된다.
PictureCallback jpegCallback = new PictureCallback() {
public void onPictureTaken(byte[] data, Camera camera) {
FileOutputStream outStream = null;
try {
imageFilePath = getFilename();
InputStream is = new ByteArrayInputStream(data);
Bitmap bmp = BitmapFactory.decodeStream(is);
// Getting width & height of the given image.
if (bmp != null) {
int w = bmp.getWidth();
int h = bmp.getHeight();
// Setting post rotate to 90
Matrix mtx = new Matrix();
mtx.postRotate(90);
// Rotating Bitmap
Bitmap rotatedBMP = Bitmap.createBitmap(bmp, 0, 0, w, h, mtx, true);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
rotatedBMP.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] byteArray = stream.toByteArray();
outStream = new FileOutputStream(String.format(imageFilePath, System.currentTimeMillis()));
outStream.write(byteArray);
outStream.close();
} else {
outStream = new FileOutputStream(String.format(imageFilePath, System.currentTimeMillis()));
outStream.write(data);
outStream.close();
}
preview.camera.startPreview();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
}
}
};
Android 라이브 필터 만들기
Live Filter란 Still Image를 중간에 가로채서 효과를 적용 시킨 이미지로서, 이를 실시간으로 화면에 보여주는 것을 말한다.
- 라이브 필터 만들기 #4 YUV Format 이란: Android_camera_live_filter4.pdf
- 라이브 필터 만들기 #5 Live Filter 구현하기: Android_camera_live_filter5.pdf
- 라이브 필터 만들기 #6 구현 (JAVA): Android_camera_live_filter6.pdf
- 라이브 필터 만들기 #7:구현 (library - C/C++ 구현): Android_camera_live_filter7.pdf
- 라이브 필터 만들기 #8 OpenGLES 2.0 사용하기: Android_camera_live_filter8.pdf
Example
- android.hardware.Camera:OpenGLES: 안드로이드에서 GLSurfaceView를 사용한 카메라 프리뷰 사용방법.
- android.hardware.Camera:Save: 안드로이드에서 사진찍고, 저장하는 방법.
- android.hardware.Camera:Preview: 안드로이드에서 카메라 프리뷰를 출력하는 간단한 Activity.
See also
Favorite site
- Developer.android.com CAMERA
- 안드로이드 카메라 프리뷰를 올리는 방법 1
- [추천] Render camera preview using OpenGL ES 2.0 on Android 2
- 동영상 풀소스 분석. 동영상 녹화방법에 대한 설명 3
- 안드로이드 영상녹화 예제
- 안드로이드 폰에서 동영상(mp4)을 녹화하는 예제 4
- Android NV21 Bitmap 변환
- Android developer ImageFormat.NV21
- android camera에서 오는 YUV420
- Android JNI/NDK Camera (YUV420 to RGB, RGBA)
- Android YUV420 Format
- 카메라를 이용하여 사진찍고, Bitmap 받아오고 ImageView에 뿌리기 5
- Android 사진찍고 저장하는 방법
- 안드로이드 카메라 제어의 기본 6
- How to use camera view with OpenGLES 7
- OpenGL을 이용한 카메라미리보기 가이드라인
- Android에서 Camera의 Preview를 Opengl에서 보여주기. (NV21포맷 관련)
- 커니의 안드로이드: 카메라를 이용하자! SurfaceView에 대한 이해
- Android Camera Picture Size 선택 방법 8
- [추천] SurfaceView 의 이해와 CameraView 띄우기
- [추천] 영상처리 NDK 단에서 처리하여 리턴하기(Image Processing in NDK)
- 안드로이드 카메라 사진 rgb색상 추출 하는법
- Camera Preview is not FULL SCREEN in android
- Capture only that part of the camera preview(decodeYUV)
- 안드로이드 카메라 프리뷰 최적화 맞추기
- Android camera preview NV21 Bitmap 변환
- 스마트폰 카메라에서 받는 영상
- Android Surface Camera Preview 표시
- Android에서 Camera의 Preview를 Opengl에서 보여주기
- 안드로이드 카메라 영상 데이터 변환
- Android 1.6 2.0 2.1 ~1.5버전 이상에서 바뀐 카메라 업데이트
- Stackoverflow: Android Camera without Preview
- Stackoverflow: Android SDK - Get raw preview camera image without displaying it
- [추천] Render camera preview using OpenGL ES 2.0 on Android
- 사진찍기와 카메라 미리보기: 카메라 미리보기 주요과정
- [추천] Hello world - Android에서 기본 카메라 앱 연동