ZXing.Net
ZXing.Net copied to clipboard
Fix for Unity Demo as Web Cam Texture is 16x16 and The Demo Does Not Work
The problem is that the web cam texture starts up with a resolution of 16x16 and the example code does not wait until the resolution is actually set. So the reader is looking at a tiny 16x16 portion of the data and will never "see" the image appropriately.
A quick fix to modify the demo:
void Update()
{
if (camTexture.width <= 16) return;
W = camTexture.width;
H = camTexture.height;
// ... and then the rest
The actual version of the method "Update" is the following:
void Update()
{
if (c == null)
{
c = camTexture.GetPixels32();
}
// encode the last found
var textForEncoding = LastResult;
if (shouldEncodeNow &&
textForEncoding != null)
{
var color32 = Encode(textForEncoding, encoded.width, encoded.height);
encoded.SetPixels32(color32);
encoded.Apply();
shouldEncodeNow = false;
}
}
Perhaps it should be changed to this one here? What do you think?
void Update()
{
if (c == null)
{
c = camTexture.GetPixels32();
W = camTexture.width;
H = camTexture.height;
}
/// ... and the rest here like above
}