Spanish [SOLUCIONADO]sacar foto.

mvera

Active Member
Licensed User
Longtime User
hola baje un codigo para sacar fotos.
http://www.b4x.com/forum/basic4andr...rials/6891-take-pictures-internal-camera.html

el tema es que me funciona perfecto cuando ocupo el codigo bajado. Ahora cuando adapto el código para mi aplicación falla y da el siguiente error , espero me puedan orientar

B4X:
Error occurred on line: 28 (fotos)
java.lang.ClassCastException: android.widget.Button cannot be cast to android.view.SurfaceView
    at anywheresoftware.b4a.objects.CameraW.shared(CameraW.java:97)
    at anywheresoftware.b4a.objects.CameraW.Initialize(CameraW.java:52)
    at map.ieidesign.fotos._activity_resume(fotos.java:366)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:636)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:302)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:238)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:121)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:171)
    at map.ieidesign.fotos.afterFirstLayout(fotos.java:106)
    at map.ieidesign.fotos.access$100(fotos.java:17)
    at map.ieidesign.fotos$WaitForLayout.run(fotos.java:78)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:158)
    at android.app.ActivityThread.main(ActivityThread.java:7224)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1230)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1120)




y este código que puse.


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

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.

End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Dim pic As ResizePicture
    Dim camara1 As Camera
    Private pfoto As Panel
    Private bfoto3 As Button
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("foto")
   
End Sub

Sub Activity_Resume
    camara1.Initialize(pfoto, "camara1")   'LINEA 28 DEL ERROR
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    camara1.Release
End Sub


Sub camara_Ready(Success As Boolean)
    If Success Then
    camara1.StartPreview
    bfoto3.Enabled = True
    Else
    ToastMessageShow("No se puede activar la cámara", True)
    End If
End Sub

Sub camara_PictureTaken(Data() As Byte)
   
   
    camara1.StartPreview
    Dim salida As OutputStream
    Dim nomepath As String = File.DirRootExternal
   
    salida = File.OpenOutput(File.DirRootExternal,"foto.jpg",False)
    salida.WriteBytes(Data,0,Data.Length)
    salida.Close
    ToastMessageShow("Imagen guardada en: " & File.Combine(File.DirRootExternal,"foto.jpg"), True)
    bfoto3.Enabled = True
   
   
    pic.resize( nomepath, "foto.jpg", 300, 400, nomepath, "vedi1","jpeg","yes")
 
   
   
End Sub




Sub bfoto3_Click
   
    camara1.TakePicture
   
   
End Sub
 

bgsoft

Well-Known Member
Licensed User
Longtime User
Hola

No has inicializado el panel pfoto

Por otro lado te aconsejo que emplees la clase camEx que te da mas opciones

Saludos
 
Top