Forum Xamarin.Android

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

Save image to gallery

H9KH9K GBMember

Hi guys,

I'm trying to save an image I've downloaded from the net to the users gallery. Here's the code I'm using


public void SaveToCameraRoll()

    {



        var dir = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryDcim);

        var pictures = dir.AbsolutePath + "/Camera";



        var filename = System.IO.Path.Combine (pictures, System.IO.Path.GetFileName(path));



        foreach (string s in System.IO.Directory.GetFiles(System.IO.Path.GetDirectoryName(filename)))

            Console.WriteLine ("File Found:" + s);



        FileStream fs = new FileStream (path, FileMode.Open);



        Byte[] b = new byte[fs.Length];

        fs.Read (b, 0, (int)fs.Length);

        System.IO.File.WriteAllBytes (filename, b);



        if (System.IO.File.Exists(filename))

            {

            FileInfo fi = new FileInfo(filename);

            Console.WriteLine("File Size: " + fi.Length);

                              }

        else

            Console.WriteLine ("NO FILE!");





    }

The file gets written but if I open the Gallery app it doesn't show the image. If I use a File Explorer then it sees the file and I can open it using the gallery app.

So is there a flag on the file I need to set to allow the Gallery app to see it automatically?

Thanks for reading,

Hal

Posts

Sign In or Register to comment.