Android编程中调⽤Camera时预览画⾯有旋转问题的解决
⽅法
本⽂实例讲述了Android编程中调⽤Camera时预览画⾯有旋转问题的解决⽅法。分享给⼤家供⼤家参考,具体如下:
在调⽤Camera写应⽤的时候,前后摄像头的情况有时候是不⼀样的。有时候,明明后摄像头没有问题,⽽调⽤到前摄像头时,却倒转了180°,或者其他⾓度,百思不得其解。在查看了Android源码之后,发现它的解决办法很是好,接下来贴个源码,以备⽇后查看。
public static int getDisplayRotation(Activity activity) {
int rotation = WindowManager().getDefaultDisplay()
.getRotation();
pang
switch (rotation) {
ca Surface.ROTATION_0: return 0;
euruscapable
ca Surface.ROTATION_90: return 90;fra
ca Surface.ROTATION_180: return 180;
冰棍英文ca Surface.ROTATION_270: return 270;
prevent是什么意思}
return 0;
}
public static void tCameraDisplayOrientation(Activity activity,
toms
int cameraId, Camera camera) {
// See android.hardware.Camera.tCameraDisplayOrientation for
// documentation.
Camera.CameraInfo info = new Camera.CameraInfo();
int degrees = getDisplayRotation(activity);
mat
2020全国英语四六级考试时间int result;
if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
result = (ientation + degrees) % 360;
result = (360 - result) % 360; // compensate the mirror
} el { // back-facing
result = (ientation - degrees + 360) % 360;
}
camera.tDisplayOrientation(result);fuckaway
}
在调⽤Camera的时候只要调⽤tCameraDisplayOrientation这个⽅法就可以了。
希望本⽂所述对⼤家Android程序设计有所帮助。