首页 > 解决方案 > 如何使用跨媒体进行多次拍照

问题描述

如何使用 Crossmedia 进行多重拍照,我使用它,它工作得很好,但它会一次又一次地导航,但我不想要这个

bool isCamera = true;
while (isCamera)
{
file = await MediaPicker.TakePhotoAsync(new StoreCameraMediaOptions { SaveToAlbum = true, Name = "", Directory = "" });
if (file != null)
{
//save code}
else{
isCamera=false;
}

标签: xamarin.formsxamarin.androidxamarin.ios

解决方案


该插件不支持多选。所以我们需要为每个平台使用依赖服务来实现它。

自己从画廊中挑选媒体。检查本教程

安卓版

public void OpenGallery()
{
    try
    {
        var imageIntent = new Intent(Intent.ActionPick);
        imageIntent.SetType("image/*");
        imageIntent.PutExtra(Intent.ExtraAllowMultiple, true);
        imageIntent.SetAction(Intent.ActionGetContent);
        ((Activity)Forms.Context).StartActivityForResult(Intent.CreateChooser(imageIntent, "Select photo"), OPENGALLERYCODE);
        Toast.MakeText(Xamarin.Forms.Forms.Context, "Tap and hold to select multiple photos.", ToastLength.Short).Show();
    }
    catch (Exception ex)
    {
        Console.WriteLine(ex.ToString());
        Toast.MakeText(Xamarin.Forms.Forms.Context, "Error. Can not continue, try again.", ToastLength.Long).Show();
    }
}

对于 iOS,您可以使用插件https://github.com/roycornelissen/GMImagePicker.Xamarin


推荐阅读