Android上人像模式下的Zxing摄像头
我想在Android上人像模式下的Zxing摄像头,android,zxing,landscape-portrait,Android,Zxing,Landscape Portrait,我想在Zxing的相机上显示肖像方向 如何做到这一点?以下是它的工作原理 步骤1:在解码(字节[]数据,整数宽度,整数高度)中的buildLuminanceSource(..)之前添加以下行以旋转数据 DecodeHandler.java: byte[] rotatedData = new byte[data.length]; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++)
Zxing
的相机上显示肖像
方向
如何做到这一点?以下是它的工作原理
步骤1:在解码(字节[]数据,整数宽度,整数高度)中的buildLuminanceSource(..)
之前添加以下行以旋转数据
DecodeHandler.java:
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;
PlanarYUVLuminanceSource source = activity.getCameraManager().buildLuminanceSource(rotatedData, width, height);
步骤3:在
initFromCameraParameters(…)中禁用横向模式检查
CameraConfigurationManager.java
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;
//remove the following
if (width < height) {
Log.i(TAG, "Display reports portrait orientation; assuming this is incorrect");
int temp = width;
width = height;
height = temp;
}
camera.setDisplayOrientation(90);
第5步:不要忘记将活动方向设置为纵向。例如:清单它是如何工作的
步骤1:在解码(字节[]数据,整数宽度,整数高度)中的buildLuminanceSource(..)
之前添加以下行以旋转数据
DecodeHandler.java:
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;
PlanarYUVLuminanceSource source = activity.getCameraManager().buildLuminanceSource(rotatedData, width, height);
步骤3:在initFromCameraParameters(…)中禁用横向模式检查
CameraConfigurationManager.java
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;
//remove the following
if (width < height) {
Log.i(TAG, "Display reports portrait orientation; assuming this is incorrect");
int temp = width;
width = height;
height = temp;
}
camera.setDisplayOrientation(90);
第5步:不要忘记将活动方向设置为纵向。例如:manifest您可以使用我的zxlib分叉。我只禁用了横向模式。您可以设置横向/纵向,并查看正确的相机视图。您可以使用我的zxlib叉子。我只禁用了横向模式。您可以设置横向/纵向并查看正确的相机视图。这应该是与上述解决方案同步的版本
这应该是与上述解决方案同步的版本
要支持旋转活动时的所有方向和自动更改,只需修改CameraManager.java类即可
并从CaptureActivity.java
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;
//remove the following
if (width < height) {
Log.i(TAG, "Display reports portrait orientation; assuming this is incorrect");
int temp = width;
width = height;
height = temp;
}
camera.setDisplayOrientation(90);
在CameraManager.java中创建此变量:
int resultOrientation;
setCameraDisplayOrientation(context, Camera.CameraInfo.CAMERA_FACING_BACK, theCamera);//this can be set after camera.setPreviewDisplay(); in api13+.
将此添加到openDriver(..)方法:
int resultOrientation;
setCameraDisplayOrientation(context, Camera.CameraInfo.CAMERA_FACING_BACK, theCamera);//this can be set after camera.setPreviewDisplay(); in api13+.
****创建此方法****
链接:
****现在修改getFramingRectInPreview()****
并修改此方法公共平面UV亮度源建筑亮度源(..)
if(resultOrientation==180 | | resultOrientation==0){//TODO:这是在横向模式下使用相机
//去吧,假设是你,而不是死。
返回新的平面UV亮度源(数据、宽度、高度、rect.left、rect.top、rect.width()、rect.height()、false);
}否则{
byte[]rotatedData=新字节[data.length];
对于(int y=0;y
要支持旋转活动时的所有方向和自动更改,只需修改CameraManager.java类即可
并从CaptureActivity.java
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;
//remove the following
if (width < height) {
Log.i(TAG, "Display reports portrait orientation; assuming this is incorrect");
int temp = width;
width = height;
height = temp;
}
camera.setDisplayOrientation(90);
在CameraManager.java中创建此变量:
int resultOrientation;
setCameraDisplayOrientation(context, Camera.CameraInfo.CAMERA_FACING_BACK, theCamera);//this can be set after camera.setPreviewDisplay(); in api13+.
将此添加到openDriver(..)方法:
int resultOrientation;
setCameraDisplayOrientation(context, Camera.CameraInfo.CAMERA_FACING_BACK, theCamera);//this can be set after camera.setPreviewDisplay(); in api13+.
****创建此方法****
链接:
****现在修改getFramingRectInPreview()****
并修改此方法公共平面UV亮度源建筑亮度源(..)
if(resultOrientation==180 | | resultOrientation==0){//TODO:这是在横向模式下使用相机
//去吧,假设是你,而不是死。
返回新的平面UV亮度源(数据、宽度、高度、rect.left、rect.top、rect.width()、rect.height()、false);
}否则{
byte[]rotatedData=新字节[data.length];
对于(int y=0;y
对于zxing 3.0,工作库
用于纵向模式
感谢您为zxing 3.0提供的工作库
用于纵向模式
感谢您添加camera.setDisplayOrientation(90)在CameraConfigurationManager.java中的code>为我工作。添加camera.setDisplayOrientation(90)我认为最好的只使用库的解决方案是这个
您可以将其作为项目的依赖项以maven格式包含在build.gradle中
dependencies {
compile ''me.sudar:zxing-orient:2.1.1@aar''
}
我认为最好的图书馆唯一的解决方案是这个
您可以将其作为项目的依赖项以maven格式包含在build.gradle中
dependencies {
compile ''me.sudar:zxing-orient:2.1.1@aar''
}
除了@roylee的修改,我还必须将以下内容应用于CameraConfiguration Manager.java
,以获得最佳的预览和二维码识别质量
diff --git a/android/src/com/google/zxing/client/android/camera/CameraConfigurationManager.java b/android/src/com/google/zxing/client/android/camera/CameraConfigurationManager.java
index cd9d0d8..4f12c8c 100644
--- a/android/src/com/google/zxing/client/android/camera/CameraConfigurationManager.java
+++ b/android/src/com/google/zxing/client/android/camera/CameraConfigurationManager.java
@@ -56,21 +56,24 @@ public final class CameraConfigurationManager {
Display display = manager.getDefaultDisplay();
int width = display.getWidth();
int height = display.getHeight();
- // We're landscape-only, and have apparently seen issues with display thinking it's portrait
+ // We're landscape-only, and have apparently seen issues with display thinking it's portrait
// when waking from sleep. If it's not landscape, assume it's mistaken and reverse them:
+ /*
if (width < height) {
Log.i(TAG, "Display reports portrait orientation; assuming this is incorrect");
int temp = width;
width = height;
height = temp;
}
+ */
screenResolution = new Point(width, height);
Log.i(TAG, "Screen resolution: " + screenResolution);
- cameraResolution = findBestPreviewSizeValue(parameters, screenResolution, false);
+ cameraResolution = findBestPreviewSizeValue(parameters, screenResolution, true);//
Log.i(TAG, "Camera resolution: " + cameraResolution);
}
void setDesiredCameraParameters(Camera camera) {
+ camera.setDisplayOrientation(90);
Camera.Parameters parameters = camera.getParameters();
if (parameters == null) {
@@ -99,7 +102,7 @@ public final class CameraConfigurationManager {
Point getScreenResolution() {
return screenResolution;
}
-
+
public void setFrontCamera(boolean newSetting) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean currentSetting = prefs.getBoolean(PreferencesActivity.KEY_FRONT_CAMERA, false);
@@ -109,12 +112,12 @@ public final class CameraConfigurationManager {
editor.commit();
}
}
-
+
public boolean getFrontCamera() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
return prefs.getBoolean(PreferencesActivity.KEY_FRONT_CAMERA, false);
}
-
+
public boolean getTorch() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
return prefs.getBoolean(PreferencesActivity.KEY_FRONT_LIGHT, false);
@@ -181,7 +184,14 @@ public final class CameraConfigurationManager {
Camera.Size defaultSize = parameters.getPreviewSize();
bestSize = new Point(defaultSize.width, defaultSize.height);
}
+
+ // FIXME: test the bestSize == null case!
+ // swap width and height in portrait case back again
+ if (portrait) {
+ bestSize = new Point(bestSize.y, bestSize.x);
+ }
return bestSize;
+
}
private static String findSettableValue(Collection<String> supportedValues,
diff--git a/android/src/com/google/zxing/client/android/camera/CameraConfigurationManager.java b/android/src/com/google/zxing/client/android/camera/CameraConfigurationManager.java
索引cd9d0d8..4f12c8c 100644
---a/android/src/com/google/zxing/client/android/camera/CameraConfigurationManager.java
+++b/android/src/com/google/zxing/client/android/camera/CameraConfigurationManager.java
@@-56,21+56,24@@public final class CameraConfiguration Manager{
Display Display=manager.getDefaultDisplay();
int width=display.getWidth();
int height=display.getHeight();
-//我们只是一个风景画,而且很明显,我们看到了一些问题,认为这是一幅肖像画
+//我们只是一个风景画,而且很明显,我们已经看到了显示器的问题,认为它是p