最近在搞一个关于条形码扫描的软件,需求需要扫描时是竖屏。
最后在zxing官方wiki上面找到解决办法。基本思路如下。
There are 4 relative files:
1, manifest.xml, you need to make CaptureActivity portrait.

2, DecodeHandler.java, rotate data before buildLuminanceSource, it works becuase in YCbCr_420_SP and YCbCr_422_SP, the Y channel is planar and appears first

平板视图 打印 ?
1 byte[] rotatedData = new byte[data.length];
2 for (int y = 0; y < height; y++) {
3 for (int x = 0; x < width; x++)
4 rotatedData[x * height + height - y - 1] = data[x + y * width];
5 }

3, CameraManager.java, getFramingRectInPreview() need to be modified.

平板视图 打印 ?
1 rect.left = rect.left * cameraResolution.y / screenResolution.x;
2 rect.right = rect.right * cameraResolution.y / screenResolution.x;
3 rect.top = rect.top * cameraResolution.x / screenResolution.y;
4 rect.bottom = rect.bottom * cameraResolution.x / screenResolution.y;

4, CameraConfigurationManager.java, set camera orientation to portrait in setDesiredCameraParameters() use

平板视图 打印 ?
1 parameters.set("orientation", "portrait");

注:版本兼容请看下面。
and in getCameraResolution(), you need to swap x and y, because camera preview size is something like 480*320, other than 320*480.

平板视图 打印 ?
1 int tmp = cameraResolution.x;
2 cameraResolution.x = cameraResolution.y;
3 cameraResolution.y = tmp;
4 return cameraResolution;

说明:
关于摄像头旋转90度的时候,不同的sdk版本方法不同。
兼容方法如下
(所在文件:CameraConfigurationManager.java)

平板视图 打印 ?
01 if (Integer.parseInt(Build.VERSION.SDK) >= <IMG class=wp-smiley alt=8) src="http://www.andcoder.com/wp-includes/images/smilies/icon_cool.gif">
02 setDisplayOrientation(camera, 90);
03 else {
04 if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
05 parameters.set("orientation", "portrait");
06 parameters.set("rotation", 90);
07 }
08 if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
09 parameters.set("orientation", "landscape");
10 parameters.set("rotation", 90);
11 }
12 }
13
14 protected void setDisplayOrientation(Camera camera, int angle) {
15 Method downPolymorphic;
16 try {
17 downPolymorphic = camera.getClass().getMethod(
18 "setDisplayOrientation", new Class[] { int.class });
19 if (downPolymorphic != null)
20 downPolymorphic.invoke(camera, new Object[] { angle });
21 } catch (Exception e1) {
22 }
23 }

更多相关文章

  1. Fragment 视图重绘问题
  2. Android新特性之TabLayout+ViewPager悬停
  3. Dialogplus——简单的Android(安卓)dialog对话框控
  4. 实习入职第二十天:Android(安卓)中文 API(123) —— AbsListView
  5. Android(安卓)中keyEvent的消息处理
  6. Android(安卓)Studio中如何新建assets文件夹
  7. Android(安卓)中文 API(123) —— AbsListView(一)
  8. 关于setVisibility的几个常量
  9. Android中的oast的使用

随机推荐

  1. android中gps的使用以及解析nmea0183协议
  2. android 在调用执行了reboot系统层做部分
  3. 系出名门Android(7) - 控件(View)之ZoomC
  4. Android 相机拓展库,能够实时采集并且识别
  5. android中使用DisplayMetrics获取屏幕参
  6. Android keystore 调试
  7. Android仿微信QQ群头像生成
  8. Android如何接收locale改变的消息 || loc
  9. Android(安卓)AsyncTask 完美解析 看不懂
  10. ubuntu 14.04 adb 配置及使用