Spanish no puedo guardar una foto, me guarda un archivo de 0 bytes

rscheel

Well-Known Member
Licensed User
Longtime User
Podrías dejar tu código, así es difícil saber tu problema.
 

Manolo

Member
Licensed User
perdon soy nuevo, me explico quiero abrir la camara por defecto del mobil hacer foto y poder aceptar o cancelar, hasta ahi todo correcto. pero si le doy aceptar deberia guardar la foto y no lo hace, me crea un archivo 0 bytes. el codigo esta en el ejemplo del link que he pasado antes. si no se puede con este metodo me puedes explicar otro. graciaaaaaaassssssssssssssssssss

#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
 

rscheel

Well-Known Member
Licensed User
Longtime User
Hay una opción en al momento que escribes para agregar código de fuente, por favor inserta el código con esa opción.

 

Manolo

Member
Licensed User
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
 

rscheel

Well-Known Member
Licensed User
Longtime User
graciass, tambien es la primera vez que escribo en el foro
Tu problema son 2 lineas que comentaste, descomentalas y funcionara.

B4X:
ImageView1.Bitmap = LoadBitmapSample(File.DirRootExternal, "1.jpg",ImageView1.Width, ImageView1.Height) 'Descomenta esta linea

B4X:
i.PutExtra("output", ParseUri("file://" & File.Combine(Directory, PictureName))) 'Descomenta esta linea

Ese es tu problema.
 

Manolo

Member
Licensed User
ya lo hize y no funciona, no se si me falta alguna libreria. imageview lo comente porque me daba error
 

rscheel

Well-Known Member
Licensed User
Longtime User
El proyecto es bien, necesitas tener estas 2 librerías, a mi me funciona perfecto en moto x play android 6.0, si no te funciona puede que sea tu dispositivo.

 

rscheel

Well-Known Member
Licensed User
Longtime User
La alternativa es que uses CameraExClass, creas tu propia cámara.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…