I use this code below to open the gallery, get a image and crop using the internal tool to crop.
I made a few change to uses the in the SDK = 26, like runtime permissions.
The old function to crop the image uses "GetPathFromContentResult" (that don't works in SDK = 26, works fine until SDK = 23) and @Erel says "it is a mistake to use this sub", in this post:
https://www.b4x.com/android/forum/t...s-returned-from-contentchooser.39313/#content
I tried several changes in code of the cropPicture sub to work, after select the image in gallery, but without success.
How can I fix this problem?
Thanks in advance.
I made a few change to uses the in the SDK = 26, like runtime permissions.
The old function to crop the image uses "GetPathFromContentResult" (that don't works in SDK = 26, works fine until SDK = 23) and @Erel says "it is a mistake to use this sub", in this post:
https://www.b4x.com/android/forum/t...s-returned-from-contentchooser.39313/#content
I tried several changes in code of the cropPicture sub to work, after select the image in gallery, but without success.
How can I fix this problem?
Thanks in advance.
B4X:
Sub Button1_Click
Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_READ_EXTERNAL_STORAGE)
End Sub
Sub Activity_PermissionResult (Permission As String, Result As Boolean)
If Permission = Starter.rp.PERMISSION_READ_EXTERNAL_STORAGE Then GetImage
End Sub
Sub GetImage
cc.Show("image/*", "Select Photo")
End Sub
Sub cc_Result (Success As Boolean, Dir As String, FileName As String)
If Success Then
'If show the image in ImageView, without crop, works
ImgPhoto.Bitmap = LoadBitmapSample(Dir, FileName, ImgPhoto.Width, ImgPhoto.Height)
'If I try to crop, don't works in SDK = 26
cropPicture(FileName)
End If
End Sub
Sub cropPicture(SelectedPhoto As String)
Dim i As Intent
i.Initialize("com.android.camera.action.CROP", ParseUri("file://" & GetPathFromContentResult(SelectedPhoto)))
i.SetType("image/*")
i.PutExtra("crop", "true")
i.PutExtra("aspectX", 1)
i.PutExtra("aspectY", 1)
i.PutExtra("output", ParseUri("file://" & File.Combine(Starter.rp.GetSafeDirDefaultExternal(""), "photo1.jpg")))
StartActivityForResult(i)
End Sub
Sub ParseUri(FileName As String) As Object
Dim r As Reflector
Return r.RunStaticMethod("android.net.Uri", "parse", Array As Object(FileName), Array As String("java.lang.String"))
End Sub
Sub StartActivityForResult(i As Intent)
Dim jo As JavaObject = GetBA
ion = jo.CreateEvent("anywheresoftware.b4a.IOnActivityResult", "ion", Null)
jo.RunMethod("startActivityForResult", Array As Object(ion, i))
End Sub
Sub GetBA As Object
Dim jo As JavaObject
Dim cls As String = Me
cls = cls.SubString("class ".Length)
jo.InitializeStatic(cls)
Return jo.GetField("processBA")
End Sub
Sub ion_Event (MethodName As String, Args() As Object) As Object
If Args(0) = -1 Then
ImgPhoto.Bitmap = LoadBitmapSample(Starter.rp.GetSafeDirDefaultExternal(""), "photo1.jpg", ImgPhoto.Width, ImgPhoto.Height)
End If
Return Null
End Sub