带有xamarin文件夹的图像

时间:2018-06-28 16:26:32

标签: c# android xamarin android-image

我试图在Visual Studio 2017跨平台中创建包含图像的文件夹,然后将其复制到设备上,然后访问该文件夹以显示图像。 到目前为止,我是使用嵌入式资源来完成此操作的,但这对我来说不起作用,因为现在我想将图像上传到同一文件夹中。

如何在安装应用程序时使用图像创建文件夹?

这就是我读取文件的方式。

 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

1 个答案:

答案 0 :(得分:1)

如果要将这些图像保存在真实的文件夹中,则可以将其提取并保存到应用程序Environment.GetFolderPath (Environment.SpecialFolder.Personal);文件夹中。

此页面显示了部署数据库时的操作方法,但是任何嵌入式资源都将以相同的方式工作。

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

相关问题