출처: http://developer.android.com/reference/android/hardware/Camera.html#setDisplayOrientation(int)
public final void setDisplayOrientation (int degrees)
Since: API Level 8
Set the clockwise rotation of preview display in degrees. This affects the preview frames and the picture displayed after snapshot. This method is useful for portrait mode applications. Note that preview display of front-facing cameras is flipped horizontally before the rotation, that is, the image is reflected along the central vertical axis of the camera sensor. So the users can see themselves as looking into a mirror.
This does not affect the order of byte array passed in onPreviewFrame(byte[], Camera)
, JPEG pictures, or recorded videos. This method is not allowed to be called during preview.
If you want to make the camera image show in the same orientation as the display, you can use the following code.
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);
}
Parameters
degrees | the angle that the picture will be rotated clockwise. Valid values are 0, 90, 180, and 270. The starting position is 0 (landscape). |
---|
See Also
'Archive' 카테고리의 다른 글
동시성을 고려한 설계를 공부하면 코딩실력에 도움이 되는 이유 (0) | 2011.10.04 |
---|---|
세부사항을 코드에서 몰아내라 (0) | 2011.10.03 |
Java 필드 초기화 (0) | 2011.10.03 |
디미터 함수 법칙 (혹은 디미터 법칙) (0) | 2011.10.03 |
패키지의 순환적 의존성 (0) | 2011.10.03 |