Android Question CameraEX Work with images

Addo

Well-Known Member
Licensed User
Longtime User
i am doing the following to convert images to a string From the camera

B4X:
Sub camera_Preview(Data() As Byte)
    
Dim sendtime As Long


sendtime = DateTime.Now


If sendtime - lastsendtimecam >= 500 Then


Dim jpeg() As Byte = camera1.PreviewImageToJpeg(Data, 20)

Dim rot As Int = camera1.CurrOrient
Dim ins As InputStream
Dim bmp As Bitmap
Dim bmpresize As Bitmap


ins.InitializeFromBytesArray(jpeg, 0, jpeg.Length)
bmp.Initialize2(ins)
ins.Close
bmp = RotateImage(bmp, rot)
bmpresize = CreateScaledBitmap(bmp,320, 240)

Dim imagetostring As String
Dim imgbyets() As Byte
imgbyets =  imagetobyets(bmpresize)

imagetostring = strutls.EncodeBase64(imgbyets)

'do send if needed

lastsendtimecam = DateTime.Now


End If



End Sub


every thing seems to work but the phone is lagging too much while this procedures begins , any idea on how to enhance the performance of current code to avoid lagging freezing ?
 

JordiCP

Expert
Licensed User
Longtime User
First of all, which preview size are you using? If you are sending 320x240, and this resolution is already supported by your camera (getSupportedPreviewSizes), make sure to select it as preview size, and all previous operations will be cheaper (and some unnecessary)
Also, usually the camera gives the preview frame in landscape mode. Your final image seems also in landscape, so the rotate function seems to do nothing in this case. Worth evaluating if it takes any time, as there can be surprises.

If the above is not enough, there are additional ways to optimize it all, depending on what is causing the bottleneck. You should measure time taken by each step, also the real preview size and jpeg size: this will help to sort if the problem is due to transmission bandwidth or processing delay.--> for instance, you could directly send the JPEG encoded in base64 (if you can re-build the bitmap on the other side based on this information).
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…