文件名称:android 二维码开发,Camera竖屏问题
文件大小:2KB
文件格式:TXT
更新时间:2017-07-16 10:48:36
二维码
1、修改manifest文件,将CaptureActivity设为portrait android:screenOrientation="portrait" 2、在DecodeHandler.java文件中,找到decode(byte[],int,int)方法,在buildLuminanceSource调用前,加上如下: byte[] rotatedData = newbyte[data.length]; for(inty = 0; y < height; y++) { for(intx = 0; x < width; x++) rotatedData[x * height + height - y - 1] = data[x + y * width]; } inttmp = width; // Here we are swapping, that's the difference to #11 width = height; height = tmp; data = rotatedData; 3、在CameraManager.java中找到getFramingRectInPreview()方法, 替换相应代码: 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; 4、在CameraConfigurationManager.java里找到setDesiredCameraParameters()方法,加入代码:(这里不同的SDK版本可能调用的方法不一样) camera.setDisplayOrientation(90); 兼容版本如下: void setDesiredCameraParameters(Camera camera) { Camera.Parameters parameters = camera.getParameters(); Log.d(TAG, "Setting preview size: " + cameraResolution); parameters.setPreviewSize(cameraResolution.x, cameraResolution.y); parameters.setSceneMode(Camera.Parameters.SCENE_MODE_PORTRAIT); parameters.setRotation(90); setFlash(parameters); setZoom(parameters); // setSharpness(parameters); if (Integer.parseInt(Build.VERSION.SDK) >= 8) setDisplayOrientation(camera, 90); else { if (context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) { parameters.set("orientation", "portrait"); parameters.set("rotation", 90); } if (context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { parameters.set("orientation", "landscape"); parameters.set("rotation", 90); } } camera.setParameters(parameters); } protected void setDisplayOrientation(Camera camera, int angle) { Method downPolymorphic; try { downPolymorphic = camera.getClass().getMethod( "setDisplayOrientation", new Class[] { int.class }); if (downPolymorphic != null) downPolymorphic.invoke(camera, new Object[] { angle }); } catch (Exception e1) { } }