Android Example Native Camera + Crop - Native Galery + Crop

hi i make a simple code using the google and intent *-*

This code is very very simple and call the native crop later save the image
with native camera or galery

B4X:
#Region  Project Attributes
    #ApplicationLabel: asd
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: False
#End Region

Sub Process_Globals


End Sub

Sub Globals
    Private ImageView1 As ImageView
    Private Button1 As Button
    Private Button2 As Button
    Dim onoff As Boolean
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("1")

End Sub

Sub Activity_Resume
    If onoff = True Then
    onoff=False
    ImageView1.Visible = True
    ImageView1.Bitmap = LoadBitmapSample(File.DirRootExternal, "1.jpg",ImageView1.Width, ImageView1.Height)
    End If
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub

Sub Button1_Click
    camera(File.DirRootExternal, "1.jpg")
End Sub

Sub Button2_Click
    Galeria(File.DirRootExternal, "1.jpg")
End Sub

''''''''''''''''''''''''''''''''''''' CAMERA + CROP '''''''''''''''''''''''''''''''''''''''''''''
Sub camera(Directory As String, PictureName As String)
    Dim i As Intent
    onoff = True
    i.Initialize("android.media.action.IMAGE_CAPTURE", "" )
    i.PutExtra("crop", "true") 'crop ON
    i.PutExtra("aspectX", 0) 'crop aspects
    i.PutExtra("aspectY", 0) 'crop aspects
    i.PutExtra("outputX", 200) 'crop size
    i.PutExtra("outputY", 150) 'crop size
    i.PutExtra("output", ParseUri("file://" & File.Combine(Directory, PictureName))) 'output folder you set OpenCam(File.DirRootExternal, "1.jpg")
    StartActivity(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
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

''''''''''''''''''''''''''''''''''''' GALERY+ CROP '''''''''''''''''''''''''''''''''''''''''''''
Sub Galeria(Directory As String, PictureName As String)
    Dim i As Intent
    onoff = True
    i.Initialize(i.ACTION_PICK, "")
    i.SetType("image/*")
    i.PutExtra("output", ParseUri("file://" & File.Combine(Directory, PictureName))) 'output folder you set OpenCam(File.DirRootExternal, "1.jpg")
    i.PutExtra("crop", "true") 'crop ON
    i.PutExtra("aspectX", 0) 'crop aspects
    i.PutExtra("aspectY", 0) 'crop aspects
    i.PutExtra("outputX", 200) 'crop size
    i.PutExtra("outputY", 150) 'crop size
    StartActivity(i)

End Sub

here is a example
 

Attachments

  • MEUS EXEMPLOS.zip
    502.6 KB · Views: 6,774

fziebell

Member
Licensed User
Longtime User
Hi.
I test the code above. Works great, but.....

If i use Button1_Click in Sub Camera...
after StartActivity(i), the app will restart from new.

So i can't read the onoff Flag.

If i use Button2_Click in Sub Galeria...
after StartActivity(i), the app jumps to Activity_Resume
and i can read the onoff Flag.

Does somebody has any idea?
 

Manolo

Member
Licensed User
good afternoon , I need to open the native camera and save the image , this example works , but does not save the picture.
can you help me please
 

iCAB

Well-Known Member
Licensed User
Longtime User
Hi Guys

is there a way to adjust a single edge of the crop rectangle ( meaning either vertically only, or horizontally only)

Thank you
 

Star-Dust

Expert
Licensed User
Longtime User
thank's. Is very usefull
 

electronicajaf

Member
Licensed User
Longtime User
hi i make a simple code using the google and intent *-*

This code is very very simple and call the native crop later save the image
with native camera or galery

B4X:
#Region  Project Attributes
    #ApplicationLabel: asd
    #VersionCode: 1
    #VersionName:
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: False
    #IncludeTitle: False
#End Region

Sub Process_Globals


End Sub

Sub Globals
    Private ImageView1 As ImageView
    Private Button1 As Button
    Private Button2 As Button
    Dim onoff As Boolean
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("1")

End Sub

Sub Activity_Resume
    If onoff = True Then
    onoff=False
    ImageView1.Visible = True
    ImageView1.Bitmap = LoadBitmapSample(File.DirRootExternal, "1.jpg",ImageView1.Width, ImageView1.Height)
    End If
End Sub

Sub Activity_Pause (UserClosed As Boolean)
End Sub

Sub Button1_Click
    camera(File.DirRootExternal, "1.jpg")
End Sub

Sub Button2_Click
    Galeria(File.DirRootExternal, "1.jpg")
End Sub

''''''''''''''''''''''''''''''''''''' CAMERA + CROP '''''''''''''''''''''''''''''''''''''''''''''
Sub camera(Directory As String, PictureName As String)
    Dim i As Intent
    onoff = True
    i.Initialize("android.media.action.IMAGE_CAPTURE", "" )
    i.PutExtra("crop", "true") 'crop ON
    i.PutExtra("aspectX", 0) 'crop aspects
    i.PutExtra("aspectY", 0) 'crop aspects
    i.PutExtra("outputX", 200) 'crop size
    i.PutExtra("outputY", 150) 'crop size
    i.PutExtra("output", ParseUri("file://" & File.Combine(Directory, PictureName))) 'output folder you set OpenCam(File.DirRootExternal, "1.jpg")
    StartActivity(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
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''

''''''''''''''''''''''''''''''''''''' GALERY+ CROP '''''''''''''''''''''''''''''''''''''''''''''
Sub Galeria(Directory As String, PictureName As String)
    Dim i As Intent
    onoff = True
    i.Initialize(i.ACTION_PICK, "")
    i.SetType("image/*")
    i.PutExtra("output", ParseUri("file://" & File.Combine(Directory, PictureName))) 'output folder you set OpenCam(File.DirRootExternal, "1.jpg")
    i.PutExtra("crop", "true") 'crop ON
    i.PutExtra("aspectX", 0) 'crop aspects
    i.PutExtra("aspectY", 0) 'crop aspects
    i.PutExtra("outputX", 200) 'crop size
    i.PutExtra("outputY", 150) 'crop size
    StartActivity(i)

End Sub

here is a example
No logro en Android nuevos que CAMERA + CROP cambie el tamaño al que le expesifico en
i.PutExtra("outputX", 200) 'crop size
i.PutExtra("outputY", 150) 'crop size
Como se hace ahora??
 
Top