微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

将图库中的多个图像导入 xamarin 表单应用程序并将它们显示在我的内容页面上

如何解决将图库中的多个图像导入 xamarin 表单应用程序并将它们显示在我的内容页面上

我的用例要求用户从他的设备库中选择多张照片,并将所选图像显示为我的 xamarin 表单应用程序中的网格视图。我已经使用设备相机完成了拍照并显示在应用程序上拍摄的照片,但这一次只是一张照片。拍照代码如下。

 public async void DoTakePhoto()
    {
      try
      {
        VisualState = State.Loading;

        await CrossMedia.Current.Initialize();
        if (!CrossMedia.Current.IsCameraAvailable || !CrossMedia.Current.IsTakePhotoSupported)
        {
          return;
        }
       
        MediaFile file = await CrossMedia.Current.TakePhotoAsync(new Plugin.Media.Abstractions.StoreCameraMediaOptions
        {
          
          SavetoAlbum = true,Directory = "App Photo Folder",MaxWidthHeight = 2048,CompressionQuality = 50,PhotoSize = PhotoSize.MaxWidthHeight,});
       
        if (file == null && ImageSource == null)
        {
         
          return;
        }
        else if (file == null)
        {
         
          return;
        }
        
        MediawithFile = new MediumWithFile(m_ExifDataParser) {
          Id = new Guid(),Data = file,Path = file.Path,AlbumPath = file.AlbumPath,Version = 1
        };
      
      }
      catch (Exception ex)
      {
        displayAlert("B5",ex.ToString(),"B5");
        
        return;
      }
      finally
      {
        VisualState = State.None;
      }
    }

我有一个可绑定的 ImageSource 变量,如下所示:

public ImageSource ImageSource =>  MediawithFile?.Data == null ? null : ImageSource.FromFile(MediawithFile.Data.Path);

我使用以下代码在我的用户界面上显示点击的照片:

<Frame Grid.Row="0"
                   Grid.ColumnSpan="2"
                   Padding="0"
                   CornerRadius="8">
          <Image Aspect="AspectFill"
                       BackgroundColor="Transparent"
                       Source="{Binding ImageSource}" />
        </Frame>

有没有办法从图库上传多张图片并使用相同的跨媒体插件显示它们。对此的任何想法表示赞赏。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。