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);



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
由于资源太大,每次只允许我上传60M,所以一共有四个文件 后面三个是在这里: zxing-3.2.0\core\src\test\resources\blackbox ZXing ("zebra crossing") is an open-source, multi-format 1D/2D barcode image processing library implemented in Java, with ports to other languages. ## Supported Formats | 1D product | 1D industrial | 2D | ---------- | ------------- | -------------- | UPC-A | Code 39 | QR Code | UPC-E | Code 93 | Data Matrix | EAN-8 | Code 128 | Aztec (beta) | EAN-13 | Codabar | PDF 417 (beta) | | ITF | | | RSS-14 | | | RSS-Expanded | ## Components ### Active | Module | Description | ------------------- | ----------- | core | The core image decoding library, and test code | javase | JavaSE-specific client code | android | Android client Barcode Scanner [![Barcode Scanner](http://www.android.com/images/brand/android_app_on_play_logo_small.png)](https://play.google.com/store/apps/details?id=com.google.zxing.client.android) | androidtest | Android test app, ZXing Test | android-integration | Supports integration with Barcode Scanner via `Intent` | android-core | Android-related code shared among `android`, `androidtest`, `glass` | glass | Simple Google Glass application | zxingorg | The source behind `zxing.org` | zxing.appspot.com | The source behind web-based barcode generator at `zxing.appspot.com` ### Available in previous releases | Module | Description | ------ | ----------- | [cpp](https://github.com/zxing/zxing/tree/00f634024ceeee591f54e6984ea7dd666fab22ae/cpp) | C++ port | [iphone](https://github.com/zxing/zxing/tree/00f634024ceeee591f54e6984ea7dd666fab22ae/iphone) | iPhone client | [objc](https://github.com/zxing/zxing/tree/00f634024ceeee591f54e6984ea7dd666fab22ae/objc) | Objective C port | [actionscript](https://github.com/zxing/zxing/tree/c1df162b95e07928afbd4830798cc1408af1ac67/actionscript) | Partial ActionScript port | [jruby](https://github.com/zxing/zxing/tree/a95a8fee842f67fb43799a8e0e70e4c68b509c43/jruby) | JRuby wrapper ### ZXing-based third-party open source projects | Module | Description | --------------------------------------------------------------- | ----------- | [QZXing](https://sourceforge.net/projects/qzxing) | port to Qt framework | [zxing-cpp](https://github.com/glassechidna/zxing-cpp) | port to C++ (forked from the [deprecated official C++ port](https://github.com/zxing/zxing/tree/00f634024ceeee591f54e6984ea7dd666fab22ae/cpp)) | [zxing_cpp.rb](https://github.com/glassechidna/zxing_cpp.rb) | bindings for Ruby (not just JRuby), powered by [zxing-cpp](https://github.com/glassechidna/zxing-cpp) | [ZXing .NET](http://zxingnet.codeplex.com/) | port to .NET and C#, and related Windows platform ### Other related third-party open source projects | Module | Description | ---------------------------------------------- | ----------- | [Barcode4J](http://barcode4j.sourceforge.net/) | Generator library in Java | [ZBar](http://zbar.sourceforge.net/) | Reader library in C99 | [Zint](http://sourceforge.net/projects/zint/) | Generator library in C99 ## Links * [Online Decoder](http://zxing.org/w/decode.jspx) * [QR Code Generator](http://zxing.appspot.com/generator) * [Javadoc](http://zxing.github.io/zxing/apidocs/) * [Documentation Site](http://zxing.github.io/zxing/) * [Google+](https://plus.google.com/u/0/b/105889184633382354358/105889184633382354358/posts) ## Contacting Post to the [discussion forum](https://groups.google.com/group/zxing) or tag a question with [`zxing` on StackOverflow](http://stackoverflow.com/questions/tagged/zxing). ## Etcetera [![Build Status](https://travis-ci.org/zxing/zxing.png?branch=master)](https://travis-ci.org/zxing/zxing) [![Coverity Status](https://scan.coverity.com/projects/1924/badge.svg)](https://scan.coverity.com/projects/1924) [![codecov.io](https://codecov.io/github/zxing/zxing/coverage.svg?branch=master)](https://codecov.io/github/zxing/zxing?branch=master) QR code is trademarked by Denso Wave, inc. Thanks to Haase & Martin OHG for contributing the logo. Optimized with [![JProfiler](http://www.ej-technologies.com/images/banners/jprofiler_small.png)](http://www.ej-technologies.com/products/jprofiler/overview.html)

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值