Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OnPreviewFrame(IntPtr data, Camera camera) is not being called #11

Open
JJwilkin opened this issue Jul 14, 2020 · 0 comments
Open

OnPreviewFrame(IntPtr data, Camera camera) is not being called #11

JJwilkin opened this issue Jul 14, 2020 · 0 comments

Comments

@JJwilkin
Copy link

Hello, I am trying to access the frames of the preview on Android using this Library, and then passing the FastJavaByteArray to Zxing's Decode() method to scan for a barcode in a specific area of the preview. The preview is working fine, and when I use the normal Preview.SetPreviewCallback(this); it works fine and the OnPreviewFrame(byte[], Camera) gets called. It's just when I use Preview.SetNonMarshalingPreviewCallback(this) that the method isn't being called. I'm not to sure why this is happening and I wanted to use this so I could scan for a barcode frame by frame using Zxing. I've attached my code below.

`public void Open() {
if (!closed) return;
try {
Preview = Camera.Open();
}
catch (Exception e) {
Console.WriteLine(e);
}

		var parameters = Preview.GetParameters();

		int numBytes = (parameters.PreviewSize.Width * parameters.PreviewSize.Height * Android.Graphics.ImageFormat.GetBitsPerPixel(parameters.PreviewFormat)) / 8;
		using (FastJavaByteArray buffer = new FastJavaByteArray(numBytes))
			Preview.AddCallbackBuffer(new FastJavaByteArray(numBytes));

		var options = new ZXing.Mobile.MobileBarcodeScanningOptions();
		options.PossibleFormats.Add(BarcodeFormat.QR_CODE);
		barcodeReader = options.BuildBarcodeReader();

        Preview.SetNonMarshalingPreviewCallback(this);
        //Preview.SetPreviewCallback(this);


        Handler handler = new Handler();
        Action loop = null;
        loop = () =>
        {
            if (!closed)
            {
                AutoFocusLoop();
                
                handler.PostDelayed(loop, (long)(1000 * AF_DELAY));
            }
        };
        handler.Post(loop);

        closed = false;
    }

public void OnPreviewFrame(IntPtr data, Camera camera)
{
//Generate FastJavaByteArray and use Zxing Decode()
}

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant