Android Question Burst mode photos using Camera2 Library

sunish

Member
Licensed User
Longtime User
Camera2 API documentation mentions about burst mode. Is it supported by the B4A implementation of the library ? If so, can sample code be provided for detecting whether the phone supports burst mode and how to invoke it ?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Try this:
Add to main module:
B4X:
Sub TakeMultiplePhotos
   Try
       SetState(openstate, True, VideoMode)
       Wait For(cam.TakePicturesNow(MyTaskIndex, 9)) Complete (Pictures As List)
       SetState(openstate, False, VideoMode)
       pnlPicture.RemoveAllViews
       For r = 0 To 2
           For c = 0 To 2
               Dim data() As Byte = Pictures.Get(r * 3 + c)
               Dim bmp As Bitmap = cam.DataToBitmap(data)
               Dim iv As ImageView
               iv.Initialize("")
               pnlPicture.AddView(iv, c * pnlPicture.Width / 3, r * pnlPicture.Height / 3, _
                   pnlPicture.Width / 3, pnlPicture.Height / 3)
               iv.Bitmap = bmp.Resize(iv.Width, iv.Height, True)
               iv.Gravity = Gravity.CENTER
           Next
       Next
       pnlBackground.SetVisibleAnimated(100, True)
       Sleep(4000)
       pnlBackground.SetVisibleAnimated(500, False)
   Catch
       HandleError(LastException)
   End Try
End Sub

Add to CamEx2:
B4X:
Public Sub TakePicturesNow (MyTaskIndex As Int, NumberOfPictures As Int) As ResumableSub
   If MyTaskIndex <> TaskIndex Then Return False
   Camera.AbortCaptures
   Dim builder As JavaObject = Camera.CreateCaptureBuilder
   Dim SensorOrientation As Int = GetFromCameraCharacteristic("SENSOR_ORIENTATION")
   Dim front As Int = 1
   If getIsFrontFacingCamera Then front = -1
   Dim orientation As Int = (SensorOrientation + jcamera.GetField("lastKnownOrientation") * front + 360) Mod 360
   CaptureSettingMap.Put("JPEG_ORIENTATION", orientation)
   SetSettingsFromMap(builder, CaptureSettingMap)
   Dim result As List
   result.Initialize
   For i = 1 To NumberOfPictures
       Camera.AddCaptureRequest(builder)
   Next
   For i = 1 To NumberOfPictures
       Wait For Camera_PictureTaken (Data() As Byte)
       result.Add(Data)
   Next
   StartPreview(MyTaskIndex, False)
   Return result
End Sub

It is based on the same method as TakePictureNow. It sends multiple requests at once.
 
Upvote 0

sunish

Member
Licensed User
Longtime User
Great, it seems to work. Now what's the optimal way to save the image list to files. I could find the function, DataToFile in the library, but how to pass the list item as byte array for the function ?
 
Upvote 0
Top