void SelectImageFromGallery(string localUrl, string remoteUrl, string fileName) { if (ProfileImageButton == null) { return; } var vc = new GalleryImagePicker(); vc.Canceled += (s, e) => { vc.DismissViewController(true, null); }; vc.FinishedPickingMedia += (object s, UIImagePickerMediaPickedEventArgs e) => { switch (e.Info[UIImagePickerController.MediaType].ToString()) { case "public.image": Console.WriteLine("Image selected"); var me = RealmUserServices.GetMe(false); ProfileImageButton.SetImage(UIImage.FromBundle(FallbackImageFileName), new UIControlState()); ProfileImageButton.ShowLoadingIndicators(); UIImage originalImage = e.Info[UIImagePickerController.OriginalImage] as UIImage; var smallerImage = ImageUtils.ScaledToSize(originalImage, new CGSize(200, 200)); var bytes = ImageUtils.ByteArrayFromImage(smallerImage, 100); S3Utils.UploadPhoto(bytes, localUrl, remoteUrl, fileName, () => { SDWebImageManager.SharedManager.ImageCache.RemoveImage(me.RemoteProfileImageURL, true, null); ProfileImageButton.SetImageWithCustomCache(me.GetRemoteProfileImageUrlCached(), FallbackImageFileName, FallbackImageFileName, me.RemoteProfileImageURL); }, null); break; case "public.video": Console.WriteLine("Video selected"); break; } vc.DismissViewController(true, null); }; PresentViewController(vc, true, null); }
void DownloadFacebookImage(string localUrl, string remoteUrl, string fileName) { if (ProfileImageButton == null) { return; } var me = RealmUserServices.GetMe(false); if (me == null) { return; } var url = me.GetFacebookProfilePictureUrl(); if (url == null) { return; } ProfileImageButton.SetImage(UIImage.FromBundle(FallbackImageFileName), new UIControlState()); ProfileImageButton.ShowLoadingIndicators(); SDWebImageManager.SharedManager.ImageDownloader.DownloadImage(NSUrl.FromString(url), SDWebImageDownloaderOptions.HighPriority, null, (image, data, error, finished) => { if (image == null || error != null) { ProfileImageButton.ShowLoadingIndicators(); return; } var bytes = ImageUtils.ByteArrayFromImage(image, 100); S3Utils.UploadPhoto(bytes, localUrl, remoteUrl, fileName, () => { SDWebImageManager.SharedManager.ImageCache.RemoveImage(me.RemoteProfileImageURL, true, null); ProfileImageButton.SetImageWithCustomCache(me.GetRemoteProfileImageUrlCached(), FallbackImageFileName, FallbackImageFileName, me.RemoteProfileImageURL); }, null); }); }