Skip to content

Instantly share code, notes, and snippets.

@unitycoder
Last active August 17, 2021 07:25
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unitycoder/6e7866eec8cd864be0f3c036ff1ab57b to your computer and use it in GitHub Desktop.
Save unitycoder/6e7866eec8cd864be0f3c036ff1ab57b to your computer and use it in GitHub Desktop.
Read QR Barcode From Texture File with ZXing
using UnityEngine;
using System.Collections;
using ZXing;
public class ReadBarcodeFromFile : MonoBehaviour
{
public Texture2D inputTexture; // Note: [x] Read/Write must be enabled from texture import settings
void Start()
{
// create a barcode reader instance
IBarcodeReader reader = new BarcodeReader();
// get texture Color32 array
var barcodeBitmap = inputTexture.GetPixels32();
// detect and decode the barcode inside the Color32 array
var result = reader.Decode(barcodeBitmap, inputTexture.width, inputTexture.height);
// do something with the result
if (result != null)
{
Debug.Log(result.BarcodeFormat.ToString());
Debug.Log(result.Text);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment