Search code examples
c#androidxamarinandroid-image

Images with xamarin folder


I am trying to create a folder with images in visual studio 2017 cross-platform and copy the folder on the device and then access it to show the images. So far I was doing it with embedded resource but this is not working for me as now i want to upload images in the same folder.

How to create a folder with the images on installation of the app?

This is how i was reading the files.

 var resourceName = assembly.GetManifestResourceNames();

        for (int columnrow = 0; columnrow < resourceName.Length; columnrow++)
        {

            for (int rowIndex = 0; rowIndex < 2; rowIndex++)
            {

                if (counter >= resourceName.Length)
                {
                    break;
                }


                var img = new Image
                {
                    Source = FileImageSource.FromResource(resourceName[counter]),
                    Aspect = Aspect.Fill,


                };
                var tapGestureRecognizer = new TapGestureRecognizer();
                tapGestureRecognizer.Tapped += (sender, e) =>
                {
                        // cast to an image
                        Image theImage = (Image)sender;
                    Navigation.PushModalAsync(new ImageViewPopUp(theImage));

                        // now you have a reference to the image
                    };

                img.GestureRecognizers.Add(tapGestureRecognizer);

                // ImageList.ColumnDefinitions[rowIndex] = new ColumnDefinition { Width = new GridLength(700,GridUnitType.Star)};
                ImageList.Children.Add(img, rowIndex, columnrow);
                counter++;

            }
        }

enter image description here

enter image description here


Solution

  • If you want these images in a real folder, you can extract them and save them to your applications Environment.GetFolderPath (Environment.SpecialFolder.Personal); folder.

    This page shows how to do it when deploying an database, but any embedded resource will work in the same way.

    https://robgibbens.com/deploying-a-database-file-with-a-xamarin-forms-app/