Android Question Saving a Picture to the Gallery

Discussion in 'Android Questions' started by colboy, Nov 16, 2018.

  1. colboy

    colboy Member Licensed User

    I'm using the following code to save an image to the gallery.

    Code:
    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
     
  2. ronell

    ronell Well-Known Member Licensed User

    i tried the code. works without issue
    Code:
    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?
     
  3. Erel

    Erel Administrator Staff Member Licensed User

Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice