Public Sub PreviewImageToJpeg(data() As Byte, quality As Int) As Byte()
Dim size, previewFormat As Object
r.target = parameters
size = r.RunMethod("getPreviewSize")
previewFormat = r.RunMethod("getPreviewFormat")
r.target = size
Dim width = r.GetField("width"), height = r.GetField("height") As Int
Dim yuvImage As Object = r.CreateObject2("android.graphics.YuvImage", _
Array As Object(data, previewFormat, width, height, Null), _
Array As String("[B", "java.lang.int", "java.lang.int", "java.lang.int", "[I"))
r.target = yuvImage
Dim rect1 As Rect
rect1.Initialize(0, 0, r.RunMethod("getWidth"), r.RunMethod("getHeight"))
Dim out As OutputStream
out.InitializeToBytesArray(100)
r.RunMethod4("compressToJpeg", Array As Object(rect1, quality, out), _
Array As String("android.graphics.Rect", "java.lang.int", "java.io.OutputStream"))
Return out.ToBytesArray
End Sub