Android Camera后摄像头视频传输显示左右mirror

yantao_lu 2014-07-10 10:13:13
在Android上做了个视频电话,当切换到后摄像头时,本地显示的视频没有问题,但是传输到另一个手机的视频数据是左右mirror的。请问哪位牛人知道如何调整camera的mirror,只看到Camera有setDisplayOrientation(degree)函数,参数只是degree,不知道如何左右翻转,请高人指点,多谢!
...全文
1097 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
yantao_lu 2014-07-11
  • 打赏
  • 举报
回复
monodin, 你贴的第一段代码我也看过,其中的“compensate the mirror”十分令我费解,“(360 - result) % 360”只是变换了角度,怎么和mirror相关呢?还请解释一下
monodin 2014-07-11
  • 打赏
  • 举报
回复
我没做过视频,不过从描述猜测是前后置摄像头切换的问题,希望以下方法能帮到你

	public static int getDisplayOrientation(int degrees, int cameraId) {
		// See android.hardware.Camera.setDisplayOrientation for
		// documentation.
		Camera.CameraInfo info = new Camera.CameraInfo();
		Camera.getCameraInfo(cameraId, info);
		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;
		}
		return result;
	}
楼主用上面代码获取Camera Preview的方向,然后调用setDisplayOrientation设置 上述方法的degree默认是0,一般手机不用改,有些手机硬件确实存在方向不对的bug,需要自行调试后选择对应的degree cameraId可以通过下面方法获取,其中-1表示不支持任何摄像头
	
	public static int getCameraId(boolean front) {
		int num = Camera.getNumberOfCameras();
		for (int i = 0; i < num; i++) {
			CameraInfo info = new CameraInfo();
			Camera.getCameraInfo(i, info);
			if (info.facing == CameraInfo.CAMERA_FACING_FRONT && front) {
				return i;
			}
			if (info.facing == CameraInfo.CAMERA_FACING_BACK && !front) {
				return i;
			}
		}
		return -1;
	}
lr21shiji 2014-07-11
  • 打赏
  • 举报
回复
你要判断你的手机摄像头的摄像方向,然后做反转
Darcy杨 2014-07-11
  • 打赏
  • 举报
回复
另一个手机在展示的时候反转一下吧

80,350

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧