Private Sub TakePicture (TargetWidth As Int, TargetHeight As Int)
Dim i As Intent
i.Initialize("android.media.action.IMAGE_CAPTURE", "")
File.Delete(Provider.SharedFolder, tempImageFile)
Dim u As Object = Provider.GetFileUri(tempImageFile)
i.PutExtra("output", u) 'the image will be saved to this path
Try
Wait For (CallSub(KeepRunningService, "Start")) Complete (Unused As Boolean)
StartActivityForResult(i)
Wait For ion_Event (MethodName As String, Args() As Object)
CallSub(KeepRunningService, "Stop")
Dim bmp As B4XBitmap
If -1 = Args(0) Then
Try
Dim in As Intent = Args(1)
If File.Exists(Provider.SharedFolder, tempImageFile) Then
Dim Exif As ExifData
Exif.Initialize(Provider.SharedFolder, tempImageFile)
bmp = LoadBitmapSample(Provider.SharedFolder, tempImageFile, Max(TargetWidth, TargetHeight), Max(TargetWidth, TargetHeight))
' You can copy the tempimagefile to whereever you want....
Log("Orientation: " & Exif.getAttribute(Exif.TAG_ORIENTATION))
Select Exif.getAttribute(Exif.TAG_ORIENTATION)
Case Exif.ORIENTATION_ROTATE_180 '3
bmp = bmp.Rotate(180)
Case Exif.ORIENTATION_ROTATE_90 '6
bmp = bmp.Rotate(90)
Case Exif.ORIENTATION_ROTATE_270 '8
bmp = bmp.Rotate(270)
End Select
bmp = bmp.Resize(TargetWidth, TargetHeight, True)
Else If in.HasExtra("data") Then 'try to get thumbnail instead
Dim jo As JavaObject = in
bmp = jo.RunMethodJO("getExtras", Null).RunMethod("get", Array("data"))
End If
Catch
Log(LastException)
End Try
End If
CallSubDelayed3(Me, "Image_Available", bmp.IsInitialized, bmp)
Catch
ToastMessageShow("Camera is not available.", True)
Log(LastException)
CallSubDelayed3(Me, "Image_Available", False, Null)
End Try
End Sub