ZXing竖屏扫描-创新互联
zxing实现竖屏扫描
第一步:修改AndroidManifest清单文件,删除AndroidManifest中CaptureActivity的screenOrientation属性:
成都创新互联公司专注于德清企业网站建设,响应式网站建设,商城建设。德清网站建设公司,为德清等地区提供建站服务。全流程按需网站策划,专业设计,全程项目跟踪,成都创新互联公司专业和态度为您提供的服务第二步:删除CaptureActivity中把onResume方法中的无用代码:
// if (prefs.getBoolean(PreferencesActivity.KEY_DISABLE_AUTO_ORIENTATION, true)) { // setRequestedOrientation(getCurrentOrientation()); // } else { // setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); // }
第三步:在CaptureActivity中把onCreate方法结尾处添加代码:
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } else { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); }
if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); } else { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); }
第四步:在CameraConfigurationManager的setDesiredCameraParameters方法中添加代码:
camera.setDisplayOrientation(90);//add 这句代码作用是旋转镜头90度,使相机预览方向正确显示 camera.setParameters(parameters);
camera.setDisplayOrientation(90);//add 这句代码作用是旋转镜头90度,使相机预览方向正确显示 camera.setParameters(parameters);
第五步:修改CameraManager中getFramingRectInPreview方法:
// 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; 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;
// 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; 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;
第六步:修改DecodeHandler中的decode(byte[] data, int width, int height)方法:
在
PlanarYUVLuminanceSource source = activity.getCameraManager().buildLuminanceSource(data, width, height);
PlanarYUVLuminanceSource source = activity.getCameraManager().buildLuminanceSource(data, width, height);
前添加代码
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; data = rotatedData;
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; data = rotatedData;
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
网站名称:ZXing竖屏扫描-创新互联
URL地址:http://cdiso.cn/article/dheeph.html