简体   繁体   English

如何使用xamarin.forms从图库中为Android和iOS设备选择多个图像?

[英]How to select multiple images from gallery for android and iOS device using xamarin.forms?

I am working on xamarin.forms. 我正在研究xamarin.forms。 I am creating an app that can run on Android and iOS both. 我正在创建一个可以在Android和iOS上运行的应用程序。 I have to select multiple images from gallery for both devices. 我必须从两个设备的库中选择多个图像。

But, I am unable to select multiple images at a time. 但是,我无法一次选择多个图像。 I can select single image with help of media picker ( CrossMedia ). 我可以借助媒体选择器( CrossMedia )选择单个图像。

Please update me how I can select multiple images from gallery for both devices using xamarin.forms? 请更新我如何使用xamarin.forms从两个设备的库中选择多个图像?

Regards, Anand Dubey 此致,Anand Dubey

Firstly for select multiple images in Xamarin Forms, you should do a dependency service for each platform. 首先,对于在Xamarin Forms中选择多个图像,您应该为每个平台执行依赖服务。

In Android use: 在Android中使用:

.PutExtra (Intent.ExtraAllowMultiple, true);

Ex: 例如:

  [assembly: Xamarin.Forms.Dependency (typeof (MediaService))]
  namespace MyProject
  {
  public class MediaService : Java.Lang.Object, IMediaService
  {
    public MediaService ()
    {
    }

    public void OpenGallery()
    {

        Toast.MakeText (Xamarin.Forms.Forms.Context, "Select max 20 images", ToastLength.Long).Show ();
        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"), 0);



       }

     }
   }

In IOS: 在IOS中:

Install this control: ELCImagePicker

And: 和:

[assembly: Xamarin.Forms.Dependency (typeof (MediaService))]
namespace MyProject
{
public class MediaService: IMediaService, IMessanger
{

    public MediaService ()
    {
    }
    public void OpenGallery()
    {

        var picker = ELCImagePickerViewController.Instance;
        picker.MaximumImagesCount = 15;

        picker.Completion.ContinueWith (t => {
            picker.BeginInvokeOnMainThread(()=>
                {
                    //dismiss the picker
                    picker.DismissViewController(true,null);

                    if (t.IsCanceled || t.Exception != null) {
                    } else {
                        Util.File.Path = new List<string>();

                        var items = t.Result as List<AssetResult>;
                        foreach (var item in items) {
                            Util.File.Path.Add (item.Path);
                        }

                        MessagingCenter.Send<IMessanger> (this, "PostProject");
                    }
                });
        });
        var topController = UIApplication.SharedApplication.KeyWindow.RootViewController;
        while (topController.PresentedViewController != null) {
            topController = topController.PresentedViewController;
        }
        topController.PresentViewController (picker, true, null);
    }
  }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用xamarin.forms从Android设备库中选择多个图像 - Multiple image selection from Android device gallery with xamarin.forms 如何在Xamarin.Forms中显示设备存储中的图像? - How to show images from device storage in Xamarin.Forms? 如何在Xamarin IOS中使用GMImagePicker从图库中选择多张图片? - How to select multiple picture from gallery using GMImagePicker in xamarin IOS? 如何从 Xamarin Forms 中的图库中 select 多张图片并保存到所需的文件路径? - How to select multiple images from gallery in Xamarin Forms and save to desired file path? 从Android和IOS访问默认照片库并在Xamarin.Forms中显示 - Access default photo gallery from Android and IOS and display in Xamarin.Forms Xamarin.forms 如何添加拍照功能或从图库中选择照片 - Xamarin.forms how I can add ability to take photo or select it from Gallery Xamarin.Forms - 在 Android 和 Z1BDF605991920DB141ZCBDF8508204 中创建应用快捷方式 - Xamarin.Forms - Create app shortcut in Android and iOS device Xamarin.Forms-iOS-用于在UIButton上放置多个图像的自定义效果 - Xamarin.Forms - iOS - Custom effect to place multiple images on UIButton Xamarin.Forms Android将图像保存到图库 - Xamarin.Forms Android save image to gallery Xamarin.Forms iOS使用图像创建动画 - Xamarin.Forms iOS Create animation using images
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM