protected async virtual void imageSelect() { this.IsBusy = true; await CrossMedia.Current.Initialize(); if (!CrossMedia.Current.IsTakePhotoSupported) { await dialogService.DisplayAlertAsync("No Camera", "No camera available.", "OK"); this.IsBusy = false; return; } var file = await CrossMedia.Current.PickPhotoAsync(new Plugin.Media.Abstractions.PickMediaOptions { PhotoSize = Plugin.Media.Abstractions.PhotoSize.MaxWidthHeight, MaxWidthHeight = 500 }); if (file == null) { this.IsBusy = false; return; } this.Group.GroupImage = CustomImageSource.FromByteArray(() => { var stream = file.GetStream(); var byteArray = Utils.ReadStram(stream); file.Dispose(); return(byteArray); }); this.IsBusy = false; }
private static async Task setImageSourceFromBlob(GroupItem item) { var buffer = await downloadFile(item.Id, container_name_group); // replace if not defference image if (buffer != null && !buffer.EqualArray(item.GroupImage.StreamByte)) { item.GroupImage = CustomImageSource.FromByteArray(() => { return(buffer); }); // save as loadfile await saveImageByteToLocal(item.Id, container_name_group, buffer); } }
public static async Task SetImageSource(GroupItem item) { ///// set from local var buffer = await getImageByteFromLocal(item.Id, container_name_group); if (buffer != null) { item.GroupImage = CustomImageSource.FromByteArray(() => { return(buffer); }); } ///// set from Azure blob (not wait) setImageSourceFromBlob(item); }
//constructor public SettingViewModel(INavigationService navigationService, IPageDialogService dialogService) : base(navigationService, dialogService) { this.User = GlobalAttributes.User; Task.Run(() => Service.ImageService.SetImageSource(this.User)); if (this.User.UserImage == null) { this.User.UserImage = CustomImageSource.FromFile(Constants.IconAccountName); } SettingItems = new ObservableCollection <SettingMenuVMItem>(); SettingItems.Add(new SettingMenuVMItem("Manage Group", "Manage groups that share reports.", openManageGroup)); SettingItems.Add(new SettingMenuVMItem("See the Source Code", "Access GitHub to see the source code of APO-Chan.", openGithub)); SettingItems.Add(new SettingMenuVMItem("About us", "Access ExceedOne Homepage.", openExcedOne)); SettingItems.Add(new SettingMenuVMItem("Version", Xamarin.Forms.DependencyService.Get <IAssemblyService>().GetVersionName(), versionStub)); SettingItems.Add(new SettingMenuVMItem("SignOut", "SignOut From APO-Chan.", navigateSignOut)); }
public async Task <CustomImageSource> GetImage(string url, bool overwrite = false, bool login = false, Size size = default(Size), Action <double, double> progressAction = null, CancellationTokenSource cancelToken = null) { CustomImageSource result = new CustomImageSource(); var file = GetCacheFile(url, overwrite); var fp = string.Empty; var id = url.GetIllustId(); var fn = url.GetImageId(); if (!string.IsNullOrEmpty(file)) { result = await file.LoadImageFromFile(size); } else { file = GetImagePath(url); if (file.IsDownloading() && await file.WaitDownloading(timeout: TimeSpan.FromSeconds(30))) { result = await file.LoadImageFromFile(size); } if (result.Source == null || string.IsNullOrEmpty(result.SourcePath)) { var success = login ? await url.SaveImage(await CommonHelper.ShowLogin(), file, overwrite) : await url.SaveImage(file, overwrite, progressAction, cancelToken : cancelToken); if (success) { result = await file.LoadImageFromFile(size); } file.ClearDownloading(); } } if (!(result.Source is ImageSource) && (url.IsDownloadedAsync(out fp, true) || url.IsDownloadedAsync(out fp))) { result = await fp.LoadImageFromFile(size); } if (result.Source is ImageSource && !string.IsNullOrEmpty(id)) { var hash = result.GetHashCode(); loadedImageHashTable[hash] = id; loadedImageFileTable[hash] = fn; } return(result); }