【发布时间】:2018-04-28 06:44:17
【问题描述】:
【问题讨论】:
-
您可以参考this blog更好地理解。
-
这篇博客只展示了ZXing如何解码和编码(之前已经做过这部分),但仍然不知道如何获取模式的位置。
【问题讨论】:
使用以下代码解码ZXing dll。
private WebCamTexture camTexture;
private Rect screenRect;
void Start()
{
screenRect = new Rect(0, 0, Screen.width, Screen.height);
camTexture = new WebCamTexture();
camTexture.requestedHeight = Screen.height;
camTexture.requestedWidth = Screen.width;
if (camTexture != null)
{
camTexture.Play();
}
}
void OnGUI()
{
// drawing the camera on screen
GUI.DrawTexture(screenRect, camTexture, ScaleMode.ScaleToFit);
// do the reading — you might want to attempt to read less often than you draw on the screen for performance sake
try
{
IBarcodeReader barcodeReader = new BarcodeReader();
// decode the current frame
var result = barcodeReader.Decode(camTexture.GetPixels32(), camTexture.width, camTexture.height);
if (result != null)
{
Debug.Log("DECODED TEXT FROM QR: " +result.Text);
}
ResultPoint[] point = result.ResultPoints;
Debug.Log("X: " + point[0].X + " Y: " + point[1].Y);
}
catch (Exception ex) { Debug.LogWarning(ex.Message); }
}
我参考了ZXing dll link。它还在自述文件中有二维码生成器。通过自述文件。它几乎相同,只是添加了ResultPoint[] point = result.ResultPoints;。这给出了图像 3 个角的位置。显然,您需要在 Assets 的 plugins 文件夹中添加 ZXing.dll。
希望这有助于获得结果。
【讨论】: