gpt4 book ai didi

android - FLEX - ZXing - Android、移动 - 条码读取器

转载 作者:行者123 更新时间:2023-11-29 04:54:29 25 4
gpt4 key购买 nike

基于http://www.remotesynthesis.com/post.cfm/adding-a-qr-code-reader-in-flex-on-android和 zxing 客户端示例代码,我尝试创建一个可以读取任何类型代码的应用程序。但在我的设备上,它在使用 Qrcode 时工作正常,但不适用于任何其他类型的代码,特别是条形码;我哪里错了?这是代码 -

<?xml version="1.0" encoding="utf-8"?>
<s:View xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark" title="Scanner">

<fx:Script>
<![CDATA[
import mx.core.BitmapAsset;
import com.google.zxing.common.BitMatrix;
import com.google.zxing.BarcodeFormat;
import com.google.zxing.BinaryBitmap;
import com.google.zxing.BufferedImageLuminanceSource;
import com.google.zxing.DecodeHintType;
import com.google.zxing.MultiFormatReader;
import com.google.zxing.Result;
import com.google.zxing.client.result.ParsedResult;
import com.google.zxing.client.result.ResultParser;
import com.google.zxing.common.GlobalHistogramBinarizer;
import com.google.zxing.common.flexdatatypes.HashTable;
//import com.google.zxing.oned.EAN13Reader;
//import com.google.zxing.qrcode.QRCodeReader;

import flashx.textLayout.tlf_internal;

protected var camera:Camera;
private var videoDisplay:Video = new Video(300, 300);
private var myReader:MultiFormatReader;
private var bmd:BitmapData;
private var cameraStarted:Boolean = false;


protected function start_camera(event:MouseEvent):void
{
myReader = new MultiFormatReader();

if(!cameraStarted){
if(Camera.isSupported) {
camera = Camera.getCamera();
camera.setMode(300, 300, 15);

videoDisplay.x = 295;
sv.addChild(videoDisplay);

videoDisplay.attachCamera(camera);
videoDisplay.rotation = 90;

btn.label = "Scan Now";
lbl.text = "";
cameraStarted = true;
} else {
lbl.text = "No camera found";
}
} else {
decodeSnapshot();
}
}

public function decodeSnapshot():void {
lbl.text = "Checking...";
bmd = new BitmapData(300, 300);
bmd.draw(videoDisplay, null, null, null, null, true);
videoDisplay.cacheAsBitmap = true;
videoDisplay.cacheAsBitmapMatrix = new Matrix;
decodeBitmapData(bmd, 300, 300);
bmd.dispose();
bmd=null;
System.gc();
}

public function decodeBitmapData(bmpd:BitmapData, width:int, height:int):void {
var lsource:BufferedImageLuminanceSource = new BufferedImageLuminanceSource(bmpd);
var bitmap:BinaryBitmap = new BinaryBitmap(new GlobalHistogramBinarizer(lsource));

var ht:HashTable = null;
ht = this.getAllHints();

var res:Result = null;
try {
res = myReader.decode(bitmap, ht);
}

catch (event:Error) {

}

if (res == null) {
videoDisplay.clear();
lbl.text = "Nothing decoded";
} else {
var parsedResult:ParsedResult = ResultParser.parseResult(res);
lbl.text = parsedResult.getDisplayResult();
sv.removeChild(videoDisplay);
cameraStarted = false;
btn.label = "Start Camera";
}

}

private function getAllHints():HashTable {
var ht:HashTable = new HashTable;
//ht.Add(DecodeHintType.POSSIBLE_FORMATS, BarcodeFormat.EAN_13);
return ht;
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<s:VGroup height="100%" width="100%" top="0" right="0" bottom="0" left="0" horizontalAlign="center">
<s:VGroup width="100%" height="300" horizontalAlign="center" id="vg">
<s:SpriteVisualElement id="sv" width="300" height="200" />
</s:VGroup>
<s:VGroup horizontalAlign="center" >
<s:Button id="btn" width="220" height="36" label="Start Camera"
click="start_camera(event)"/>
<s:Label id="lbl" x="106" y="291" text=""/>
</s:VGroup>
</s:VGroup>
</s:View>

最佳答案

您的camera.setMode(300, 300, 15);错误,请使用:

this.camera.setMode( 320, 240, 15, true );

请记住,AS3 版本的检测不如 zxing 的原生 Android 代码那么强大。

编辑:读错了你的帖子,你必须添加你想要的格式的哈希并将其插入哈希数组。

关于android - FLEX - ZXing - Android、移动 - 条码读取器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8254408/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com