Search This Blog

Wednesday 20 June 2018

Multiple Image Picker in Xamarin IOS

On the click of button
private async void btnOpenGallery(object sender, EventArgs e)
{         
   DependencyService.Get<IMediaService>().GetGMImageStreamAsync();
}
 
Create Interface to open Image Picker
public interface IMediaService
{
      void GetGMImageStreamAsync();
}

In Xamarin.IOS Project implement Interface
public class MediaService: UIViewController, IMediaService
{
	public  void GetGMImageStreamAsync()
	{ 
		GMImagePickerController picker=new GMImagePickerController();
		picker.MediaTypes = new[] { PHAssetMediaType.Image };
		picker.Title = "Add Images";
		picker.CustomDoneButtonTitle = "Add";
		picker.CustomCancelButtonTitle = "Cancel";
		picker.AllowsMultipleSelection = true;
 
		picker.FinishedPickingAssets += (sender, e) => 
		{
			PHImageManager imageManager = new PHImageManager();
			PHImageRequestOptions options = new PHImageRequestOptions();
			options.DeliveryMode = PHImageRequestOptionsDeliveryMode.HighQualityFormat;
			options.ResizeMode = PHImageRequestOptionsResizeMode.Exact;
			options.Synchronous = true;
			options.NetworkAccessAllowed = true;         
			imageManager.RequestImageForAsset(asset,
			new CGSize(asset.PixelWidth, asset.PixelHeight),
			PHImageContentMode.Default,
			null,
			(image, info) => {
 
			 // var data = image.AsJPEG();
			 // byte[] imageData = data.ToArray();
 
			});  
		};
 
		/optional       
		picker.Canceled += Picker_Canceled;
		UIWindow window = UIApplication.SharedApplication.KeyWindow;
		var viewController = window.RootViewController;
		viewController.PresentModalViewController(picker, true);
	}
}

No comments:

Post a Comment

Popular Posts