我一直遵守以下的答案做到这一点。http://stackoverflow.com/a/16252917/2747591
但我没有得到我想要做的。
由于相机拍摄的图像是通过90度,而我试图扫描旋转。就像如果你使用的是相机,那么在我的手机屏幕是显示90度旋转的preVIEW点击一个人的照片。但是,这不是我想要的,因为它正在酒吧code扫描难以使用。我想preVIEW理所应当的。任何想法?
下面是我在code更改
第1步
在德codeHandler.java我加入以下code只是buildLuminanceSource之前
字节[] = rotatedData新的字节[data.length]对于(INT Y = 0; Y<高度; Y ++){ 对于(INT X = 0; X<宽度; X ++) rotatedData [X *高+高 - Y - 1] =数据[X + Y *宽]}INT TMP =宽度; //这里,我们交换,这就是区别,以#11宽度=高度;HEIGHT = tmp目录;数据= rotatedData;PlanarYUVLuminanceSource源= activity.getCameraManager()buildLuminanceSource(数据,宽,高)。
第2步
修改getFramingRectIn $ P $在CameraManager.java PVIEW()
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;
第3步
禁用风景模式initFromCameraParameters在CameraConfigurationManager.java检查(...)
的说明是删除
如果(宽度LT;高度){ Log.i(TAG,报告显示纵向;假设这是不正确); INT TEMP =宽度; 宽度=高度; 高度=温度;}
但我没有找到我的Cameraconfiguration这个文件code。因此它不应该反正无所谓
第四步
添加以下行只是定义参数应用后旋转CameraConfigurationManager.java相机setDesiredCameraParameters(...)
camera.setDisplayOrientation(90);
第5步
从变更景观CaptureActivity方向为纵向像这样我的应用程序的清单文件
<活动 机器人:名字=com.google.zxing.client.android.CaptureActivity 机器人:screenOrientation =画像 机器人:configChanges =方向| keyboardHidden 机器人:主题=@安卓风格/ Theme.NoTitleBar.Fullscreen 机器人:windowSoftInputMode =stateAlwaysHidden> &所述;意图滤光器> <作用机器人:名字=android.intent.action.MAIN/> <类机器人:名字=android.intent.category.DEFAULT/> &所述; /意图滤光器> &所述;意图滤光器> <作用机器人:名字=com.google.zxing.client.android.SCAN/> <类机器人:名字=android.intent.category.DEFAULT/> &所述; /意图滤光器> < /活性GT;
解决方案
我用zxing zxing 2.3及以下的解决方案,为我工作。
1在CameraConfigurationManager类,setDesiredCameraParameters方法下面添加下面尖线code
- > Camera.Parameters参数= camera.getParameters();
如果(context.getResources()。getConfiguration()。方向== Configuration.ORIENTATION_PORTRAIT){ camera.setDisplayOrientation(90); }
2在CameraManager类,getFramingRect方法代替code如下
INT宽度= MIN_FRAME_WIDTH; INT高度= MIN_FRAME_HEIGHT;如果(context.getResources()。getConfiguration()。方向== Configuration.ORIENTATION_PORTRAIT){ INT TMP = 7 * screenResolution.x / 8; 宽度=(TMP)LT; MIN_FRAME_WIDTH? MIN_FRAME_WIDTH:(TMP); TMP = 1 * screenResolution.y / 3; 身高=(TMP)LT; MIN_FRAME_WIDTH? MIN_FRAME_WIDTH:(?(TMP)> MAX_FRAME_HEIGHT MAX_FRAME_HEIGHT:(TMP));}其他{ //原始code 宽度= findDesiredDimensionInRange(screenResolution.x,MIN_FRAME_WIDTH,> MAX_FRAME_WIDTH); 身高= findDesiredDimensionInRange(screenResolution.y,MIN_FRAME_HEIGHT,MAX_FRAME_HEIGHT);}
3在CameraManager类,getFramingRectIn preVIEW方法代替code如下
如果(context.getResources()。getConfiguration()。方向== Configuration.ORIENTATION_PORTRAIT){ 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;}其他{ //原始code评论 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;}
4在德$ C $钱德勒类,德code方法下面添加code以下尖头行
- >结果rawResult = NULL;
如果(activity.getResources()。getConfiguration()。方向== Configuration.ORIENTATION_PORTRAIT){ 字节[] = rotatedData新的字节[data.length] 对于(INT Y = 0; Y<高度; Y ++){ 对于(INT X = 0; X<宽度; X ++) rotatedData [X *高+高 - Y - 1] =数据[X + Y *宽] } 数据= rotatedData; INT TMP =宽度; 宽度=高度; HEIGHT = tmp目录; }
请找我的工作code
http://www.compyutech.co.in/repo/zxing- dynamic.zip
希望这将帮助你....
I have followed the following answer to do this. http://stackoverflow.com/a/16252917/2747591
But I am not getting what i want to do.
The image captured by camera is rotated by 90 degree while i am trying to scan. Like if you are clicking a photo of a person using the camera, then in my phone screen it is showing the preview rotated by 90 degree. But that is not what i want as it is making bar code scanning difficult to use. I want preview as it should be. Any ideas?
Here are my changes in the code
Step 1
In DecodeHandler.java I have added the following code just before buildLuminanceSource
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);
Step 2
Modified getFramingRectInPreview() in CameraManager.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;
Step 3:
Disable the check for Landscape Mode in initFromCameraParameters(...) in CameraConfigurationManager.java
The instructions is to Remove
if (width < height) {
Log.i(TAG, "Display reports portrait orientation; assuming this is incorrect");
int temp = width;
width = height;
height = temp;
}
But I didn't find this code in my Cameraconfiguration file. so it should not matter anyways
Step 4
Added following line to rotate camera in setDesiredCameraParameters(...) in CameraConfigurationManager.java just after defining parametres
camera.setDisplayOrientation(90);
Step 5
Changed the CaptureActivity orientation from landscape to portrait in my app's manifest file like this
<activity
android:name="com.google.zxing.client.android.CaptureActivity"
android:screenOrientation="portrait"
android:configChanges="orientation|keyboardHidden"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:windowSoftInputMode="stateAlwaysHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
<intent-filter>
<action android:name="com.google.zxing.client.android.SCAN"/>
<category android:name="android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
解决方案
I have used zxing zxing 2.3 and below solution worked for me.
1 In CameraConfigurationManager class, setDesiredCameraParameters Method add below code below pointed line
-> Camera.Parameters parameters = camera.getParameters();
if (context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
camera.setDisplayOrientation(90);
}
2 In CameraManager class, getFramingRect Method replace code as below
int width = MIN_FRAME_WIDTH; int height = MIN_FRAME_HEIGHT;
if (context.getResources().getConfiguration().orientation ==Configuration.ORIENTATION_PORTRAIT) {
int tmp = 7 * screenResolution.x / 8;
width = (tmp) < MIN_FRAME_WIDTH ? MIN_FRAME_WIDTH : (tmp);
tmp = 1 * screenResolution.y / 3;
height = (tmp) < MIN_FRAME_WIDTH ? MIN_FRAME_WIDTH : ((tmp) > MAX_FRAME_HEIGHT ? MAX_FRAME_HEIGHT : (tmp));
}else{
// Original Code
width = findDesiredDimensionInRange(screenResolution.x, MIN_FRAME_WIDTH, > MAX_FRAME_WIDTH);
height = findDesiredDimensionInRange(screenResolution.y, MIN_FRAME_HEIGHT, MAX_FRAME_HEIGHT);
}
3 In CameraManager class, getFramingRectInPreview Method replace code as below
if (context.getResources().getConfiguration().orientation ==Configuration.ORIENTATION_PORTRAIT) {
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;
}else{
// Original code commented
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;
}
4 In DecodeHandler class, decode Method add below code below pointed line
-> Result rawResult = null;
if (activity.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT){
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];
}
data = rotatedData;
int tmp = width;
width = height;
height = tmp;
}
Please find my working code
http://www.compyutech.co.in/repo/zxing-dynamic.zip
Hope this will help you....