0

我的用例要求用户从他的设备库中选择多张照片,并将所选图像显示为我的 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);

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

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

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

4

0 回答 0