Skip to content

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

Description

@JJwilkin

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()
}

`

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions