Unity扫描识别二维码
用WebCamTexture 获得摄像头数据,并把他付给UI层的RawImage.这个用来展示摄像头拍摄的内容画面。
private void CreateWebcamTex(string deviceName)
{
mWebCamTexture = new WebCamTexture(deviceName,1280, 720);
rawImage.texture = mWebCamTexture;
mWebCamTexture.Play();
}
上面的函数需要传入 摄像头的名称,因为手机可能有前后置两个摄像头,需要选择后置摄像头的名称
WebCamDevice[] devices = WebCamTexture.devices;
foreach (var item in devices){
if(!item.isFrontFacing)
{
CreateWebcamTex(item.name);
break;
}
}
zxing解析摄像头texture内容
private BarcodeReader mReader;
public string Decode(Color32[] colors, int width, int height)
{
var result = mReader.Decode(colors, width, height);
if (result != null)
{
return result.Text;
}
return null;
}
没必要每帧都去识别&