19
2016
Decode QRCode with ZXing.net + Unity
Simple example to decode QRCode from texture image.
– Download XZing.net from http://zxingnet.codeplex.com/
– Unzip, Copy zxing.unity.dll from Unity/ folder into your Unity project (create Plugins/ folder and place the dll there)
– Download some QRCode image, like:
– Create new script (see source below)
– Attach script to empty gameobject
– Assign your QRCode texture into inputTexture field
– Hit Play!
– See console output:
QR_CODE goo.gl/BF4kdV
—
Your Project window structure
—
Source: ReadBarcodeFromFile.cs
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); | |
} | |
} | |
} |
Related Posts
12 Comments + Add Comment
Leave a comment
Recent posts
- [GreaseMonkey] Unity Forum Fixer
- UnityHub: Make Hub application background Translucent
- Customize SpriteShapeRenderer quality (but has issues)
- Editor tool: Copy selected gameobject’s names into clipboard as rows (for Excel)
- Editor tool: Replace string in selected gameobject’s names
- UnityHub: Enable built-in Login Dialog (no more browser login/logout issues!)
- Use TikTok-TTS in Unity (with WebRequest)
- Create Scene Thumbnail Image using OnSceneSaved & OnPreviewGUI
- webgl+javascript TTS
- Using Moonsharp (LUA) + Unity Webgl
- Using 3D gameobject prefabs with Unity Tilemap + NavMesh Surface
- Custom Unity Hub Project Template Preview Image/Video (using HTML+CSS in package description)
Recent Comments
- Vector3 maths for dummies! on
- UnityHub: Make Hub application background Translucent on
- UnityHub: Make Hub application background Translucent on
- Install Android SDK+JDK+NDK for Unity (without AndroidStudio or Unity Hub) on
- Install Android SDK+JDK+NDK for Unity (without AndroidStudio or Unity Hub) on
- [Asset Store] Point Cloud Viewer & Tools on
- [Asset Store] Point Cloud Viewer & Tools on
- ffmpeg stream raw video into Unity Texture2D on
opa!! Como faço para usar pegar a imagem da camera?
I think should work if get webcam texture into texture2D and feed that to the script..
https://docs.unity3d.com/ScriptReference/WebCamTexture.GetPixels.html
[…] Hey r/csharp, I’ve been trying to implement a QR code reader into Unity. I am a complete beginner/noob and am very new to both C# and Unity. I have been trying to use this link. […]
This is nice assets to read and generate qr/bar codes.
https://assetstore.unity.com/packages/tools/integration/qr-code-reader-and-generator-91072
please reload qrcode texture agin ….thankyou
http://vrbox.in/wp-content/uploads/2015/11/QR-Code1.jpg
i think it was just something like these,
http://www.hypergridbusiness.com/faq/vr-headset-qr-codes/
Thank yoooouu so much! Helped me a lot. Really thanks!!
how to use ZXing in Unity3D
https://github.com/linmq/ZXing_Unity3D_Test
I tried Zxing, yeah, it works. And i prefer to decode qr code in .net with CnetSDK instead: http://www.cnetsdk.com/net-barcode-generator-sdk-create-qrcode-2d-barcode.
Hello, I follow your steps exactly as you show and I get this error when I attach my QR code image to Input_Texture: ” Texture ‘Box_Number_01’ is not readable, the texture memory can not be accessed from scripts. You can make the texture readable in the Texture Import Settings.”
Probably is something I am doing wrong, but I cannot understand what. Thanks
from that texture import settings, need to set ‘[x] read/write enabled’ or something similar.
https://docs.unity3d.com/Manual/class-TextureImporter.html
You need to tick read write box