Save image to local storage

BuzzTycaBuzzTyca DEMember
edited July 2018 in Xamarin.Android

Hey guys,

I'm XamarinBeginner and I'm trying to build my first app.
Most is working pretty well, but I'm stuck on a point.
I'm trying to save an created Image but it never appears in the gallery.

Here is my code

public void Save(string directory, Bitmap bitmap) //"directory" is the directory of the original image from the gallery
        {
            int dirLength = directory.Length;
            for (int i = dirLength; i > 0; i--)
            {
                if (directory.Substring((i - 1), 1) == ".")
                {
                    directory = directory.Substring(0, i-1) + "_overlay." + directory.Substring(i);
                }
            }
            var sdCardPath = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath;
            var filePath = System.IO.Path.Combine(sdCardPath, directory);
            var stream = new FileStream(filePath, FileMode.Create);
            bitmap.Compress(Bitmap.CompressFormat.Png, 100, stream);
            stream.Close();
        }

I get no errors. Is there something missing in my code or any Bug in the emulator?

Would be great, if someone could give me an hint.

Regards Buzz

Posts

  • BerayBentesenBerayBentesen TRUniversity ✭✭✭✭

    @BuzzTyca did you check permissions ?

  • BuzzTycaBuzzTyca DEMember

    I got "Write_External_Storage"
    Do I need any more?
    An Web-Article told me, that would be enough...
    I feel like in the first days of C# :s

  • BuzzTycaBuzzTyca DEMember

    It's working now, and I have no Idea why.
    The images appeard when I restarted the Emulator.
    Maybe I need a command to update the gallery.
    I'll ask google for that...

  • Hello, I need to develop an app catalogs of objects, but do not know how to work with local images, this app must work offline, you can help me or share your project to me please.

Sign In or Register to comment.