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)
'B4XPages.GetManager.SetActivityPausedEvent("HandleCameraResult")
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))
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)
'File.Copy(Provider.SharedFolder, tempImageFile,File.DirRootExternal & "/Download",tempImageFile)
Dim cvstest As Canvas
Dim rctTest As Rect
cvstest.Initialize(ImageView1)
Exif.Initialize(Provider.SharedFolder, tempImageFile)
Dim temp As String = Exif.getAttribute(Exif.TAG_DATETIME)
rctTest.Initialize(0, 0, ImageView1.Width, ImageView1.Height)
cvstest.DrawBitmap(LoadBitmap(Provider.SharedFolder, tempImageFile), Null, rctTest)
'cvstest.DrawText("Scattata il " & DateTime.Date(DateTime.Now) &" " & DateTime.Time(DateTime.now), 10dip, 30dip, Typeface.DEFAULT, 12, Colors.Green, "LEFT")
cvstest.DrawText("Scattata il :" & temp, 2dip, 14dip, Typeface.DEFAULT, 12, Colors.Green, "LEFT")
Private Out As OutputStream
Out = File.OpenOutput(File.DirRootExternal & "/Download",Global.GetTempFilename("jpg"), False)
cvstest.Bitmap.WriteToStream(Out, 100, "PNG")
Out.Close
Catch
ToastMessageShow("Camera is not available.", True)
Log(LastException)
CallSubDelayed3(Me, "Image_Available", False, Null)
End Try
End Sub
Sub StartActivityForResult(i As Intent)
Dim jo As JavaObject = Me
jo = jo.RunMethod("getBA", Null)
ion = jo.CreateEvent("anywheresoftware.b4a.IOnActivityResult", "ion", Null)
jo.RunMethod("startActivityForResult", Array(ion, i))
End Sub