android 相机 横向,在Android上的纵向模式中的Zxing相机

fe62a7fcf18889738057cefd5dd7e2d4.png

守着一只汪

要在旋转活动时自动支持所有方向和更改,请执行此操作,您只需要修改CameraManager.java类。并从CaptureActivity.java中删除此方法getCurrentOrientation()在CameraManager.java中创建此变量:int resultOrientation;将其添加到openDriver(..)方法:setCameraDisplayOrientation(context, Camera.CameraInfo.CAMERA_FACING_BACK, theCamera);//this can be set after camera.setPreviewDisplay(); in api13+.****创建此方法****链接:http://developer.android.com/reference/android/hardware/Camera.htmlpublic static void setCameraDisplayOrientation(Context context,int cameraId, android.hardware.Camera camera) {    android.hardware.Camera.CameraInfo info = new android.hardware.Camera.CameraInfo();    android.hardware.Camera.getCameraInfo(cameraId, info);    Display display = ((WindowManager)context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();    int degrees = 0;    switch (display.getRotation()) {    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;    }    if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {        resultOrientation = (info.orientation + degrees) % 360;        resultOrientation = (360 - resultOrientation) % 360;  // compensate the mirror    } else {  // back-facing        resultOrientation = (info.orientation - degrees + 360) % 360;    }    camera.setDisplayOrientation(resultOrientation);}****现在修改getFramingRectInPreview()****if(resultOrientation == 180 || resultOrientation == 0){//to work with landScape and reverse landScape            rect.left = rect.left * cameraResolution.x / screenResolution.x;            rect.right = rect.right * cameraResolution.x / screenResolution.x;            rect.top = rect.top * cameraResolution.y / screenResolution.y;            rect.bottom = rect.bottom * cameraResolution.y / screenResolution.y;        }else{            rect.left = rect.left * cameraResolution.y / screenResolution.x;            rect.right = rect.right * cameraResolution.y / screenResolution.x;            rect.top = rect.top * cameraResolution.x / screenResolution.y;            rect.bottom = rect.bottom * cameraResolution.x / screenResolution.y;        }并修改此方法public PlanarYUVLuminanceSource buildLuminanceSource(..)if(resultOrientation == 180 || resultOrientation == 0){//TODO: This is to use camera in landScape mode        // Go ahead and assume it's YUV rather than die.        return new PlanarYUVLuminanceSource(data, width, height, rect.left, rect.top, rect.width(), rect.height(), false);    }else{        byte[] rotatedData = new byte[data.length];        for (int y = 0; y < height; y++) {            for (int x = 0; x < width; x++)                rotatedData[x * height + height - y - 1] = data[x + y * width];        }        int tmp = width;        width = height;        height = tmp;        return new PlanarYUVLuminanceSource(rotatedData, width, height, rect.left, rect.top, rect.width(), rect.height(), false);    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值