Android Question Best way for crop picture

Pooya1

Active Member
Licensed User
I saw many code about crop picture in forum
Some code have problem with permission and some code have some problem other
Please give me code for crop that working in all device
 

megzz

Member
Licensed User
Longtime User
I saw many code about crop picture in forum
Some code have problem with permission and some code have some problem other
Please give me code for crop that working in all device
to crop image,you can use Intent

B4X:
Sub cropPicture(Directory As String, PictureName As String,  PictureName2 As String)
    Dim i As Intent
    i.Initialize("com.android.camera.action.CROP","")
    i.SetType("image/*")
    i.SetComponent(ParseUri("file://" & File.Combine(Directory, PictureName)))
    i.PutExtra("crop", "true")
    i.PutExtra("aspectX", 1)
    i.PutExtra("aspectY", 1)
    i.PutExtra("output", ParseUri("file://" & File.Combine(Directory, PictureName2)))
    StartActivity(i)
End Sub
 
Upvote 0

Pooya1

Active Member
Licensed User
to crop image,you can use Intent

B4X:
Sub cropPicture(Directory As String, PictureName As String,  PictureName2 As String)
    Dim i As Intent
    i.Initialize("com.android.camera.action.CROP","")
    i.SetType("image/*")
    i.SetComponent(ParseUri("file://" & File.Combine(Directory, PictureName)))
    i.PutExtra("crop", "true")
    i.PutExtra("aspectX", 1)
    i.PutExtra("aspectY", 1)
    i.PutExtra("output", ParseUri("file://" & File.Combine(Directory, PictureName2)))
    StartActivity(i)
End Sub
Can i use InternalDir in crop?
 
Upvote 0

Pooya1

Active Member
Licensed User
This code will not work once you set targetSdkVersion to 26. You need to use file provider to share a file uri.
Erel i attach my module that i use in my apps
I dont have problem in this module
But in some device example Howeii after select image and go to crop and after crop when i try to see result,i cannot see it or picture is destroying
Only i have problem in crop
Please guide me
 

Attachments

  • PC.bas
    10 KB · Views: 253
Upvote 0
Top