Sub TakePicture
Try
SetState(openstate, True, VideoMode)
Wait For(cam.FocusAndTakePicture(MyTaskIndex)) Complete (Data() As Byte)
SetState(openstate, False, VideoMode)
cam.DataToFile(Data, VideoFileDir, "1.jpg")
Dim bmp As Bitmap = cam.DataToBitmap(Data)
Log("Picture taken: " & bmp) 'ignore
pnlBackground.SetVisibleAnimated(100, True)
B4XImageView1.Bitmap = RotateJpegIfNeeded(bmp, Data)
Sleep(4000)
pnlBackground.SetVisibleAnimated(500, False)
Catch
HandleError(LastException)
End Try
End Sub