Currently I'm using the cameraEX class to grab the preview image and process the center horizontal line to read barcodes (from the ZXing source). It works great albeit a little slow.
What I do is execute the function "PreviewImageToJpeg" (below) and then grab the center line. Convert it to B&W (get the Y value) and then adjust brightness and contrast to extract the bits (or bars).
The thing is all I really want is the YUVimage (which should be the Y frame followed by a 1/4 U frame and a 1/4 V frame). I tried to extract it from the routine below but all I get is an array of all 0 (zeros).
In fact if I could just get the center horizontal line that would even be better.
Any ideas?
'Converts a preview image formatted in YUV format to JPEG.
'Note that you should not save every preview image as it will slow down the whole process.
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.iutputStream"))
Return out.ToBytesArray
End Sub
What I do is execute the function "PreviewImageToJpeg" (below) and then grab the center line. Convert it to B&W (get the Y value) and then adjust brightness and contrast to extract the bits (or bars).
The thing is all I really want is the YUVimage (which should be the Y frame followed by a 1/4 U frame and a 1/4 V frame). I tried to extract it from the routine below but all I get is an array of all 0 (zeros).
In fact if I could just get the center horizontal line that would even be better.
Any ideas?
'Converts a preview image formatted in YUV format to JPEG.
'Note that you should not save every preview image as it will slow down the whole process.
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.iutputStream"))
Return out.ToBytesArray
End Sub