Android Question Barcode detector: "setBitmap" instead of "setImageData" does not work

peacemaker

Expert
Licensed User
Longtime User
HI, All

Barcode detector uses ImageData from camera's _Preview (data() As Byte) event:
B4X:
            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 cs As CameraSize = camEx.GetPreviewSize
            frameBuilder.RunMethod("setImageData", Array(bb, cs.Width, cs.Height,  842094169))

But if to try to use Camera2 lib - only the preview bitmap can be used:

B4X:
    Dim cs As CameraSize = cam.PreviewSize
    LastCadr = cam.GetPreviewBitmap(cs.Width, cs.Height)
    Dim frameBuilder As JavaObject
    frameBuilder.InitializeNewInstance("com/google/android/gms/vision/Frame.Builder".Replace("/", "."), Null)
  
    frameBuilder.RunMethod("setBitmap", Array(LastCadr))

But recognition does not work with such way. No errors, just nothing among barcodes is recognized.

Example to try.
Any suggestion ?
 

peacemaker

Expert
Licensed User
Longtime User
Where duplicate ? Each question as separate topic, according to the rules.
"setBitmap" does not work nevertheless any other topic.
 
Last edited:
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
It is a mistake to set the preview size to be the maximum supported size. The images will be huge. I've tested it with 1920x1080. Can probably be lower.

Add an ImageView that shows the preview image. Depending on the orientation the image might be rotated.
I was able to detect CODE 128 barcodes after rotating the image.
 
Upvote 0
Top