【发布时间】:2018-10-30 22:34:48
【问题描述】:
我有一个 C#/.Net 应用程序,可以从磁盘上的图像中解码多个 QR 码。我想在 Unity 中执行此操作,因此我导入了 zxing 插件并修改了代码,使其现在使用 Color32[],而不是 Bitmap 类(因为 Unity 不支持 System.Drawing.Bitmap) .以下是我在 Unity 中的内容:
var fileData = File.ReadAllBytes(filePath);
Texture2D texture = new Texture2D(2,2);
texture.LoadImage(fileData);
var barcodeBitmap = texture.GetPixels32 ();
LuminanceSource source = new Color32LuminanceSource (barcodeBitmap, texture.width, texture.height);
IBarcodeReader reader = new BarcodeReader ();
Result[] results = reader.DecodeMultiple (source);
if (results != null)
{
foreach (Result result in results)
{
Debug.Log(result.Text);
}
}
现在的问题是,与以前相反,结果数组总是返回空值,即使对于我已经测试过的 .Net 应用程序的非空值也是如此。任何建议将不胜感激,谢谢!
【问题讨论】:
-
尝试一步步调试你的一段代码,看看什么时候出错
-
你可以找到你需要的here。那是一个真正适用于 Unity 的二维码 API
-
想通了!