如何在黑条码android上扫描白色,(倒置可以)?

时间:2017-02-20 08:20:26

标签: android zxing barcode-scanner zbar

我想在android中的黑色条形码上扫描白色。我使用了zxing,它允许我只扫描白色的黑色。 我如何扫描和倒置条形码或使用哪个库? 谢谢你的帮助。

3 个答案:

答案 0 :(得分:2)

我通过这种方式倒转了来自相机预览的 headers = { "User-Agent": random_user_agent(), "Cookie": 'bid="' + "".join(random.sample(string.ascii_letters + string.digits, 11)) + '"; gr_user_id=42bc6859-9086-4933-9f19-8f2fc412c37a; viewed="5312099_10355142_4742942_3223711_26642036_25850008_4727293_10580248_3726306"; _ga=GA1.2.1107723060.1458721162; ll="108288"; ps=y; ue="276502214@qq.com"; dbcl2="48221338:qY8I57pvNs8"; ck=xvAF; ap=1; _pk_ref.100001.4cf6=%5B%22%22%2C%22%22%2C1487574236%2C%22https%3A%2F%2Fwww.douban.com%2Faccounts%2Flogin%3Fredir%3Dhttps%253A%252F%252Fmovie.douban.com%252Fsubject%252F2973543%252F%22%5D; _pk_id.100001.4cf6=ccee4c5d3437a382.1482239227.55.1487574252.1487571075.; _pk_ses.100001.4cf6=*; __utma=30149280.1107723060.1458721162.1487570089.1487574236.345; __utmb=30149280.0.10.1487574236; __utmc=30149280; __utmz=30149280.1487518823.338.100.utmcsr=baidu|utmccn=(organic)|utmcmd=organic; __utmv=30149280.4822; __utma=223695111.1107723060.1458721162.1487570089.1487574236.52; __utmb=223695111.0.10.1487574236; __utmc=223695111; __utmz=223695111.1487298209.35.8.utmcsr=douban.com|utmccn=(referral)|utmcmd=referral|utmcct=/accounts/login; push_noty_num=0; push_doumail_num=0; _vwo_uuid_v2=2D161B768A99F5F485C8FFD318CE8704|b630fad39ce1f3cbdb2e7e44cc9411ca' } req = urllib.request.Request( url, data = None, headers = headers )

byte[]

然后将其传递给 for (int y = 0; y < data.length; y++) { data[y] = (byte) ~data[y]; } 。我有两种方式支持,所以我平心地决定每ZXing次反转。它可能效率不高或太聪明,但在我的情况下简单而且足够好

答案 1 :(得分:2)

如果您仍在参考travelapps嵌入式zxing扫描仪, integrator.addExtra(Intents.Scan.INVERTED_SCAN, true);

答案 2 :(得分:0)

使用此代码段更新代码:

import { BarcodeFormat, HTMLCanvasElementLuminanceSource } from '@zxing/library';
  ngOnInit() {
   
    HTMLCanvasElementLuminanceSource.makeBufferFromCanvasImageData = function (canvas) {
      var imageData = canvas.getContext('2d').getImageData(0, 0, canvas.width, canvas.height);
      if(localStorage.inverted.toString()==="true"){
        
        for (var i = 0; i < imageData.data.length; i += 4) {
          var r = imageData.data[i]; // Red color lies between 0 and 255
          var g = imageData.data[i + 1]; // Green color lies between 0 and 255
          var b = imageData.data[i + 2]; // Blue color lies between 0 and 255
          var a = imageData.data[i + 3]; // Transparency lies between 0 and 255
  
          var invertedRed = 255 - r;
          var invertedGreen = 255 - g;
          var invertedBlue = 255 - b;
  
          imageData.data[i] = invertedRed;
          imageData.data[i + 1] = invertedGreen;
          imageData.data[i + 2] = invertedBlue;
        }
      }
     
      return HTMLCanvasElementLuminanceSource.toGrayscaleBuffer(imageData.data, canvas.width, canvas.height);
  };
}