Android Question CameraEX Work with images

bjfhs

Active Member
Licensed User
Longtime User
B4X:
Sub Camera1_Preview (PreviewPic() As Byte)
    If DateTime.Now > lastPreviewSaved + IntervalMs Then
        Dim jpeg() As Byte = camEx.PreviewImageToJpeg(PreviewPic, 70)
        lastPreviewSaved = DateTime.Now
       
        'sendM(jpeg)
        Dim bmp As Bitmap
        Dim ins As InputStream
        ins.InitializeFromBytesArray(jpeg, 0, jpeg.Length)
        bmp.Initialize2(ins)
        ins.Close
        ImageView1.Bitmap=bmp
    End If
End Sub
But the image not show
20200307220639.png
 
Last edited:

drgottjr

Expert
Licensed User
Longtime User
did you try imageview1.invalidate after assigning the bmp?
 
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
vis there another view in front of the imageview? is imageview1.visible = true?

by the way, i loaded your code. works fine on my device. image is displayed in imageview. i happen to use a similar Camera1_Preview sub, so it was easy to insert your code.
 
Last edited:
Upvote 0

bjfhs

Active Member
Licensed User
Longtime User
vis there another view in front of the imageview? is imageview1.visible = true?

by the way, i loaded your code. works fine on my device. image is displayed in imageview. i happen to use a similar Camera1_Preview sub, so it was easy to insert your code.
The imageview is show ,but not the real image,it show unkown color picture like below,
 

Attachments

  • 20200307220639.png
    20200307220639.png
    53.9 KB · Views: 175
Upvote 0

drgottjr

Expert
Licensed User
Longtime User
1) forget about the timing loop (for now). see if you can capture the preview just once and have it appear in the imageview. in fact, that was all i did, and it worked. if you look at the camex class and read erel's comment, you'll see that we're not supposed to use camEx.PreviewImageToJpeg(PreviewPic, 70) in a tight timing loop. i said i used a similar _preview sub, but i don't use PreviewImageToJpeg the way you do. i think that's where your problem is

2) if #1 works, then the timing loop is your problem. if #1 does not work, try to capture your preview just once, convert to a jpg and save it. see if you can load it in the image view that way. i'm not saying this is the solution for your app; but you need to know if you can at least capture the preview and save it to an image file. if you still can't see the image, then something else is going on.

i can only repeat that, except for the timing loop, i copied your code, ran it and generated a bitmap which i saw in an imageview. except for the timing loop, your code seems ok. that loop might give the device no time to breathe. expecially if you're using a big preview and a tight loop. a tiny preview might work.
 
Upvote 0

bjfhs

Active Member
Licensed User
Longtime User
I know why this happen,you need use SetPreviewSize before CommitParameters.
B4X:
       camEx.SetJpegQuality(90)
        camEx.SetPictureSize(640,480)
        camEx.SetPreviewSize(640,480)
        camEx.SetContinuousAutoFocus
        camEx.CommitParameters

        camEx.StartPreview
 
Last edited:
Upvote 0
Top