android zxing二维码横屏改竖屏
Posted zhouli_csdn
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了android zxing二维码横屏改竖屏相关的知识,希望对你有一定的参考价值。
转载请注明出处:http://blog.csdn.net/zhouli_csdn/article/details/49930323
1.修改manifest文件,将CaptureActivity的screenOrentatino设为portrait。
2.摄像头调整为竖向在CameraConfigurationManager类中添加如下方法:
protected void setDisplayOrientation(Camera camera, int angle) //mycode
Method downPolymorphic;
try
downPolymorphic = camera.getClass().getMethod("setDisplayOrientation", new Class[] int.class );
if (downPolymorphic != null)
downPolymorphic.invoke(camera, new Object[] angle );
catch (Exception e1)
e1.printStackTrace();
在CameraConfigurationManager的setDesiredCameraParameters方法中调用此方法。
setDisplayOrientation(camera, 90);//mycode
3.CameraConfigurationManager类的initFromCameraParameters方法中注释一下代码:
//这段代码用于横屏的时候+
/*if (width < height)
Log.i(TAG, "Display reports portrait orientation; assuming this is incorrect");
int temp = width;
width = height;
height = temp;
*/
4.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;*/
//竖屏模式mycode
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;
5.CameraManager类的getFramingRect方法修改:
//用于横屏时候的扫描mycode
//int width = findDesiredDimensionInRange(screenResolution.x, MIN_FRAME_WIDTH, MAX_FRAME_WIDTH);
//int height = findDesiredDimensionInRange(screenResolution.y, MIN_FRAME_HEIGHT, MAX_FRAME_HEIGHT);
//用于竖屏的扫描
int height = findDesiredDimensionInRange(screenResolution.x, MIN_FRAME_WIDTH, MAX_FRAME_WIDTH);
int width = findDesiredDimensionInRange(screenResolution.y, MIN_FRAME_HEIGHT, MAX_FRAME_HEIGHT);
6.DecodeHandler修改decode方法
在
PlanarYUVLuminanceSource source = activity.getCameraManager().buildLuminanceSource(data, width, height);之前加入一下代码
//mycode
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; // Here we are swapping, that's the difference to #11
width = height;
height = tmp;
data = rotatedData;
PlanarYUVLuminanceSource source = activity.getCameraManager().buildLuminanceSource(data, width, height);
以上是关于android zxing二维码横屏改竖屏的主要内容,如果未能解决你的问题,请参考以下文章