Last active
August 17, 2021 07:25
-
-
Save unitycoder/6e7866eec8cd864be0f3c036ff1ab57b to your computer and use it in GitHub Desktop.
Read QR Barcode From Texture File with ZXing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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