Android Question Add photos to the gallery

Itila Tumer

Active Member
Licensed User
Longtime User
I want to save my photo to the gallery.
I use the camera and phone libraries.
my problem is...
I want to see the photos I took in the gallery.
Thanks in advance for your help.

My Code...


B4X:
#Region Module Attributes
    #FullScreen: False
    #IncludeTitle: True
    #ApplicationLabel: Camera example
    #VersionCode: 1
    #VersionName:
    #SupportedOrientations: landscape
#End Region

'Activity module
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
    Dim camera1 As Camera
    Dim btnTakePicture As Button
    Dim Panel1 As Panel   
    Private btnAra As Button
    Dim  chooser As ContentChooser
    Private ImageView1 As ImageView
    Public flag As String
    Public Buffer() As Byte
End Sub

Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("1")
End Sub
Sub Camera1_Ready (Success As Boolean)
    If Success Then
        camera1.StartPreview
        btnTakePicture.Enabled = True
    Else
        ToastMessageShow("Cannot open camera.", True)
    End If
End Sub

Sub Activity_Resume
    btnTakePicture.Enabled = False
    camera1.Initialize(Panel1, "Camera1")
End Sub

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

Sub Camera1_PictureTaken (Data() As Byte)
    camera1.StartPreview
    Dim out As OutputStream
    out = File.OpenOutput(File.DirRootExternal, "1.jpg", False)
    out.WriteBytes(Data, 0, Data.Length)
    out.Close
    ToastMessageShow("Image saved: " & File.Combine(File.DirRootExternal, "1.jpg"), True)
    btnTakePicture.Enabled = True
End Sub

Sub btnTakePicture_Click
    btnTakePicture.Enabled = False
    camera1.TakePicture
End Sub

Sub btnAra_Click
    'camEx.Release
    chooser.Initialize("Chooser")
    chooser.Show("image/*", "Choose image")
End Sub

Sub Chooser_Result (Success As Boolean, Dir As String, FileName As String)
    ' Dim Query As String

    
    If Success Then

        'display the chosen image in ImageView
        Dim bmp As Bitmap
        bmp.Initialize(Dir, FileName)
        ImageView1.Bitmap = bmp
    
        'Ask user if they want to save the image to DB ..
        
        'convert the image file to a bytes array
        'flagSaveImage = True
        Dim ADD As String
        Dim UP As String
        flag=ADD
        flag=UP
        Dim InputStream1 As InputStream
        InputStream1 = File.OpenInput(Dir, FileName)
    
        Dim OutputStream1 As OutputStream
        OutputStream1.InitializeToBytesArray(1000)
    
        File.Copy2(InputStream1, OutputStream1)
    
        '    Dim Buffer() As Byte 'declares an empty array
        Buffer = OutputStream1.ToBytesArray
            
            
    End If
    
End Sub
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0
Top