Android Question Save and Load a Picture into and from the device

ciginfo

Well-Known Member
Licensed User
Longtime User
Helo,
If I want save a double in the device, I can write:
B4X:
Sub Globals
    Dim FileNUMBERS As String      : FileNUMBERS = "Sets.txt"
    Dim Number as Double
   Dim MyNumber as Double
End Sub
Sub BtnEnreg_Click
    Number = 50
    Dim List1 As List
    List1.Initialize
    List1.Add(Number)
    File.WriteList(File.DirInternal, FileNUMBERS,List1)
End Sub
And if I want to load and recover my number I can write
B4X:
Sub BtnLoad_Click
    Dim List1 As List
    If File.Exists(File.DirInternal,FileNUMBERS) Then
        List1 = File.ReadList(File.DirInternal,FileSETTINGS)
        MyNumber = List1.Get(0)
End Sub
What is the syntax to do the same thing with a picture? I want to save a picture taken with camera and load it later
B4X:
Dim MyPicture as Bitmap

Thank you
 

ciginfo

Well-Known Member
Licensed User
Longtime User
Thank you Erel. And now how to load the picture saved to put it into an imageview?
 
Upvote 0

ciginfo

Well-Known Member
Licensed User
Longtime User
Now I save photo with
B4X:
Sub SaveBitmap (b As Bitmap, myDir As String, myFileName As String)
    Dim out As OutputStream
    out = File.OpenOutput(myDir, myFileName, False)
    b.WriteToStream(out, 100, "JPEG")
    out.Flush
    out.Close
End Sub
 Sub BtnSave_Click
    SaveBitmap(lastPicture,File.DirInternal,"Foto.png")
End Sub

And I Load the saved picture with
B4X:
Sub BtnLoad_Click
    Dim bg As Bitmap = LoadBitmapResize(File.DirInternal, "Foto.png", ImageView1.Width, ImageView1.Height, True)
    ImageView1.SetBackgroundImage(bg).Gravity = Gravity.CENTER
End Sub
It seems that it does't find the path
"java.io.FileNotFoundException: /storage/3064-3162/Foto.png (No such file or directory)"
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…