Android编程中调⽤Camera时预览画⾯有旋转问题的解决
⽅法
本⽂实例讲述了Android编程中调⽤Camera时预览画⾯有旋转问题的解决⽅法。分享给⼤家供⼤家参考,具体如下:
在调⽤Camera写应⽤的时候,前后摄像头的情况有时候是不⼀样的。有时候,明明后摄像头没有问题,⽽调⽤到前摄像头时,却倒转了180°,或者其他⾓度,百思不得其解。在查看了Android源码之后,发现它的解决办法很是好,接下来贴个源码,以备⽇后查看。
public static int getDisplayRotation(Activity activity) {
int rotation = WindowManager().getDefaultDisplay()属相猪
.getRotation();
switch (rotation) {
ca Surface.ROTATION_0: return 0;
ca Surface.ROTATION_90: return 90;
ca Surface.ROTATION_180: return 180;
ca Surface.ROTATION_270: return 270;
}
return 0;
}
复古主义public static void tCameraDisplayOrientation(Activity activity,
文静>电脑键盘
int cameraId, Camera camera) {预备党员转正决议
// See android.hardware.Camera.tCameraDisplayOrientation for钓鱼钩
// documentation.
Camera.CameraInfo info = new Camera.CameraInfo();
int degrees = getDisplayRotation(activity);
int result;
if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
联想电话
result = (ientation + degrees) % 360;
result = (360 - result) % 360; // compensate the mirror
期末总结500字} el { // back-facing
result = (ientation - degrees + 360) % 360;
}
camera.tDisplayOrientation(result);
}
在调⽤Camera的时候只要调⽤tCameraDisplayOrientation这个⽅法就可以了。
希望本⽂所述对⼤家Android程序设计有所帮助。