Android Question Saving a Picture to the Gallery

colboy

Member
Licensed User
Longtime User
I'm using the following code to save an image to the gallery.

B4X:
Dim Out AsOutputStream
        Dim Out As OutputStream
        Out = File.OpenOutput(File.DirInternal, "PI.jpg", False)
        bmp.WriteToStream(Out, 100, "JPEG")
        Out.Close
       
        If File.Exists(File.DirInternal,"PI.jpg") Then
            Dim i As Intent
            i.Initialize("android.intent.action.MEDIA_SCANNER_SCAN_FILE", lFile)
            Dim p As Phone
            p.SendBroadcastIntent(i)
        End If
[/QUOTE]

I got most of this code from another thread. I'm trying this on a Galaxy Tab A and nothing seems to happen. I get no errors, but the picture doesn't end up in the gallery. I know the source file is there. Anyone have any ideas?

Colin
 

ronell

Well-Known Member
Licensed User
Longtime User
i tried the code. works without issue
B4X:
Sub Activity_Create(FirstTime As Boolean)
 

    Dim bmp As Bitmap
    bmp = LoadBitmap(File.DirAssets,"user.jpg")
 
 
    Dim Out As OutputStream
    Out = File.OpenOutput(File.DirRootExternal, "user.jpg", False)
    bmp.WriteToStream(Out, 100, "JPEG")
    Out.Close
   
    If File.Exists(File.DirRootExternal,"user.jpg") Then
        Dim i As Intent
        i.Initialize("android.intent.action.MEDIA_SCANNER_SCAN_FILE", _
"file://" & File.Combine(File.DirRootExternal, "user.jpg"))
        Dim p As Phone
        p.SendBroadcastIntent(i)
    End If

End Sub


-----
where is the source file located? did you load the image to bitmap before saving it?
 
Upvote 0
Top