Private Sub Camera1_Preview (data() As Byte)
Try
If DateTime.Now > LastPreview + IntervalBetweenPreviewsMs Then
Dim frameBuilder As JavaObject
Dim bb As JavaObject
bb = bb.InitializeStatic("java.nio.ByteBuffer").RunMethod("wrap", Array(data))
frameBuilder.InitializeNewInstance("com/google/android/gms/vision/Frame.Builder".Replace("/", "."), Null)
Dim In As InputStream
In.InitializeFromBytesArray(camEx.PreviewImageToJpeg(data, 100), 0, data.Length)
Dim bmp As Bitmap
bmp.Initialize2(In)
bmp = bmp.Rotate(90) 'I don't know why we need this - shouldn't
bmp = bmp.Crop(bmp.Width * NumberFormat(((TargetPnl.Left - QRReader.Left) / (QRReader.Width)), 2, 2), bmp.Height * NumberFormat((TargetPnl.Top / QRReader.Height), 2, 2), bmp.Width * (TargetPnl.Width / QRReader.Width), bmp.Height * (TargetPnl.Height / QRReader.Height)) 'width IS .X so (W-.X) / 2 = Left
#If Debug
TestImgView.Width = TargetPnl.Width
TestImgView.Height = TargetPnl.Height
TestImgView.Gravity = Gravity.FILL
TestImgView.SetBackgroundImage(bmp)
#End If
frameBuilder.RunMethod("setBitmap", Array(bmp)) 'instead of the setImageData line
Dim frame As JavaObject = frameBuilder.RunMethod("build", Null)
Dim SparseArray As JavaObject = detector.RunMethod("detect", Array(frame))
LastPreview = DateTime.Now
Dim Matches As Int = SparseArray.RunMethod("size", Null)
If Matches > 0 Then
Dim barcode As JavaObject = SparseArray.RunMethod("valueAt", Array(0))
Dim raw As String = barcode.GetField("rawValue")
FoundBarcode(raw)
End If
End If
Catch
Log(LastException)
StopCamera
StartCamera
End Try
End Sub