private async void LoadImage() { if (_currentTask != null) { _currentTask.Cancel(); } TaskParameter imageLoader = null; var ffSource = await FFImageSourceBinding.GetImageSourceBinding(Source).ConfigureAwait(false); if (ffSource == null) { if (internalImage != null) { await MainThreadDispatcher.Instance.PostAsync(() => { internalImage.Source = null; }); } } else if (ffSource.ImageSource == FFImageLoading.Work.ImageSource.Url) { imageLoader = ImageService.Instance.LoadUrl(ffSource.Path, TimeSpan.FromDays(CacheDuration)); } else if (ffSource.ImageSource == FFImageLoading.Work.ImageSource.CompiledResource) { imageLoader = ImageService.Instance.LoadCompiledResource(ffSource.Path); } else if (ffSource.ImageSource == FFImageLoading.Work.ImageSource.ApplicationBundle) { imageLoader = ImageService.Instance.LoadFileFromApplicationBundle(ffSource.Path); } else if (ffSource.ImageSource == FFImageLoading.Work.ImageSource.Filepath) { imageLoader = ImageService.Instance.LoadFile(ffSource.Path); } if (imageLoader != null) { // CustomKeyFactory if (CacheKeyFactory != null) { var dataContext = DataContext; imageLoader.CacheKey(CacheKeyFactory.GetKey(Source, dataContext)); } // LoadingPlaceholder if (LoadingPlaceholder != null) { var placeholderSource = await FFImageSourceBinding.GetImageSourceBinding(LoadingPlaceholder); if (placeholderSource != null) { imageLoader.LoadingPlaceholder(placeholderSource.Path, placeholderSource.ImageSource); } } // ErrorPlaceholder if (ErrorPlaceholder != null) { var placeholderSource = await FFImageSourceBinding.GetImageSourceBinding(ErrorPlaceholder); if (placeholderSource != null) { imageLoader.ErrorPlaceholder(placeholderSource.Path, placeholderSource.ImageSource); } } // Downsample if (DownsampleToViewSize && (Width > 0 || Height > 0)) { if (Height > Width) { imageLoader.DownSampleInDip(height: (int)Height); } else { imageLoader.DownSampleInDip(width: (int)Width); } } else if (DownsampleToViewSize && (MinWidth > 0 || MinHeight > 0)) { if (MinHeight > MinWidth) { imageLoader.DownSampleInDip(height: (int)MinHeight); } else { imageLoader.DownSampleInDip(width: (int)MinWidth); } } else if ((int)DownsampleHeight != 0 || (int)DownsampleWidth != 0) { if (DownsampleHeight > DownsampleWidth) { if (DownsampleUseDipUnits) { imageLoader.DownSampleInDip(height: (int)DownsampleHeight); } else { imageLoader.DownSample(height: (int)DownsampleHeight); } } else { if (DownsampleUseDipUnits) { imageLoader.DownSampleInDip(width: (int)DownsampleWidth); } else { imageLoader.DownSample(width: (int)DownsampleWidth); } } } // Downsample mode imageLoader.DownSampleMode(DownsampleMode); // RetryCount if (RetryCount > 0) { imageLoader.Retry(RetryCount, RetryDelay); } // FadeAnimation imageLoader.FadeAnimation(FadeAnimationEnabled); // TransformPlaceholders imageLoader.TransformPlaceholders(TransformPlaceholders); // Transformations if (Transformations != null && Transformations.Count != 0) { imageLoader.Transform(Transformations); } imageLoader.WithPriority(LoadingPriority); imageLoader.WithCache(CacheType); imageLoader.Finish((work) => OnFinish(new Args.FinishEventArgs(work))); imageLoader.Success((imageInformation, loadingResult) => OnSuccess(new Args.SuccessEventArgs(imageInformation, loadingResult))); imageLoader.Error((exception) => OnError(new Args.ErrorEventArgs(exception))); _currentTask = imageLoader.Into(internalImage); } }
private async void LoadImage() { if (_currentTask != null) { _currentTask.Cancel(); } TaskParameter imageLoader = null; var ffSource = await FFImageSourceBinding.GetImageSourceBinding(Source); if (ffSource == null) { if (internalImage != null) { await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { internalImage.Source = null; }); } } else if (ffSource.ImageSource == FFImageLoading.Work.ImageSource.Url) { imageLoader = ImageService.LoadUrl(ffSource.Path, TimeSpan.FromDays(CacheDuration)); } else if (ffSource.ImageSource == FFImageLoading.Work.ImageSource.CompiledResource) { imageLoader = ImageService.LoadCompiledResource(ffSource.Path); } else if (ffSource.ImageSource == FFImageLoading.Work.ImageSource.ApplicationBundle) { imageLoader = ImageService.LoadFileFromApplicationBundle(ffSource.Path); } else if (ffSource.ImageSource == FFImageLoading.Work.ImageSource.Filepath) { imageLoader = ImageService.LoadFile(ffSource.Path); } if (imageLoader != null) { // LoadingPlaceholder if (LoadingPlaceholder != null) { var placeholderSource = await FFImageSourceBinding.GetImageSourceBinding(LoadingPlaceholder); if (placeholderSource != null) { imageLoader.LoadingPlaceholder(placeholderSource.Path, placeholderSource.ImageSource); } } // ErrorPlaceholder if (ErrorPlaceholder != null) { var placeholderSource = await FFImageSourceBinding.GetImageSourceBinding(ErrorPlaceholder); if (placeholderSource != null) { imageLoader.ErrorPlaceholder(placeholderSource.Path, placeholderSource.ImageSource); } } // Downsample if (DownsampleToViewSize && (Width > 0 || Height > 0)) { if (Height > Width) { imageLoader.DownSample(height: Height.PointsToPixels()); } else { imageLoader.DownSample(width: Width.PointsToPixels()); } } else if (DownsampleToViewSize && (MinWidth > 0 || MinHeight > 0)) { if (MinHeight > MinWidth) { imageLoader.DownSample(height: MinHeight.PointsToPixels()); } else { imageLoader.DownSample(width: MinWidth.PointsToPixels()); } } else if ((int)DownsampleHeight != 0 || (int)DownsampleWidth != 0) { if (DownsampleHeight > DownsampleWidth) { imageLoader.DownSample(height: DownsampleUseDipUnits ? DownsampleHeight.PointsToPixels() : (int)DownsampleHeight); } else { imageLoader.DownSample(width: DownsampleUseDipUnits ? DownsampleWidth.PointsToPixels() : (int)DownsampleWidth); } } // Downsample mode imageLoader.DownSampleMode(DownsampleMode); // RetryCount if (RetryCount > 0) { imageLoader.Retry(RetryCount, RetryDelay); } // FadeAnimation imageLoader.FadeAnimation(FadeAnimationEnabled); // TransformPlaceholders imageLoader.TransformPlaceholders(TransformPlaceholders); // Transformations if (Transformations != null && Transformations.Count != 0) { imageLoader.Transform(Transformations); } _currentTask = imageLoader.Into(internalImage); } }
/// <summary> /// /// </summary> /// <param name="imageview">ImageViewAsync View</param> /// <param name="imageUrl">Url of the image</param> /// <param name="transform">For CircleTrancform and border white color = 1 / For RoundedTransformation(10) = 2 / For RoundedTransformation with border = 3 / For CircleTrancform and border MainColor = 4 / For RoundedTransformation(30) = 5 </param> /// <param name="downSample">DownSample the Image size by deafault its true</param> public static void Load_Image(ImageViewAsync imageview, string imagePlaceholder, string imageUrl, int transform = 0, bool downSample = true, int transformRadius = 5) { try { TaskParameter imageTrancform = ImageService.Instance.LoadCompiledResource(imagePlaceholder); if (imageUrl.Contains("d-avatar.jpg")) { imageTrancform = ImageService.Instance.LoadCompiledResource("no_profile_image.png"); } else if (imageUrl.Contains("d-cover.jpg")) { imageTrancform = ImageService.Instance.LoadCompiledResource("Cover_image.jpg"); } else if (imageUrl.Contains("http")) { if (!String.IsNullOrEmpty(imageUrl) && (imageUrl.Contains("http") || imageUrl.Contains("file://") || imageUrl.Split('/').Count() > 1)) { imageTrancform = ImageService.Instance.LoadUrl(imageUrl); } else if (!String.IsNullOrEmpty(imageUrl)) { imageTrancform = ImageService.Instance.LoadCompiledResource(imageUrl); } else { imageTrancform = ImageService.Instance.LoadCompiledResource(imagePlaceholder); } } else { var file = Android.Net.Uri.FromFile(new Java.IO.File(imageUrl)); imageTrancform = ImageService.Instance.LoadFile(file.Path); } imageTrancform.TransformPlaceholders(true).Retry(3, 5000).Error(OnError); if (downSample) { imageTrancform.DownSampleMode(InterpolationMode.Default); } if (transform == 1) { imageTrancform.Transform(new CircleTransformation(transformRadius, "#ffffff")); } if (transform == 2) { imageTrancform.Transform(new RoundedTransformation(10)); } if (transform == 3) { imageTrancform.Transform(new RoundedTransformation(10, 2, 2, 10, "#ffffff")); } if (transform == 4) { imageTrancform.Transform(new CircleTransformation(5, AppSettings.MainColor)); } if (transform == 5) { imageTrancform.Transform(new RoundedTransformation(30)); } imageTrancform.LoadingPlaceholder(imagePlaceholder, ImageSource.CompiledResource); imageTrancform.ErrorPlaceholder(imagePlaceholder, ImageSource.CompiledResource); imageTrancform.Success((information, result) => { if (information.OriginalHeight > information.OriginalWidth) { if (information.OriginalHeight > 200 && information.OriginalHeight < 400) { imageTrancform.DownSample(height: 320); imageview.SetMinimumHeight(150); } else if (information.OriginalHeight > 400 && information.OriginalHeight < 500) { imageTrancform.DownSample(height: 320); imageview.SetMinimumHeight(160); } else if (information.OriginalHeight > 500 && information.OriginalHeight < 1000) { imageTrancform.DownSample(height: 420); imageview.SetMinimumHeight(170); } if (information.OriginalHeight > 1000 && information.OriginalHeight < 2000) { imageTrancform.DownSample(width: 200); imageview.SetMinimumHeight(180); } } else { if (information.OriginalHeight > 200 && information.OriginalWidth < 500) { imageTrancform.DownSample(width: 210); imageTrancform.DownSample(height: 210); imageview.SetMinimumHeight(110); } else if (information.OriginalHeight < 500 && information.OriginalWidth < 1000) { imageTrancform.DownSample(width: 260); imageTrancform.DownSample(height: 260); imageview.SetMinimumHeight(130); imageview.SetMinimumWidth(180); } else if (information.OriginalHeight < 1000 && information.OriginalWidth < 2000) { imageTrancform.DownSample(width: information.OriginalWidth / 2); imageTrancform.DownSample(height: information.OriginalHeight / 2); imageview.SetMinimumHeight(140); imageview.SetMinimumWidth(210); } else if (information.OriginalHeight < 2000 && information.OriginalWidth < 2500) { imageTrancform.DownSample(width: information.OriginalWidth / 3); imageTrancform.DownSample(height: information.OriginalHeight / 3); imageview.SetMinimumHeight(150); imageview.SetMinimumWidth(230); } } if (transform == 2) { imageTrancform.Transform(new RoundedTransformation(10)); } }); imageTrancform.Into(imageview); } catch (Exception exception) { Console.WriteLine(exception); } }
/// <summary> /// /// </summary> /// <param name="imageview">ImageViewAsync View</param> /// <param name="imageUrl">Url of the image</param> /// <param name="transform">For CircleTrancform and border white color = 1 / For RoundedTransformation(10) = 2 / For RoundedTransformation with border = 3 / For CircleTrancform and border MainColor = 4 / For RoundedTransformation(30) = 5 </param> /// <param name="downSample">DownSample the Image size by deafault its true</param> public static void Load_Image(ImageViewAsync imageview, string imagePlaceholder, string imageUrl, int transform = 0, bool downSample = true, int transformRadius = 5) { try { TaskParameter imageTrancform = ImageService.Instance.LoadCompiledResource(imagePlaceholder); if (imageUrl.Contains("d-avatar.jpg")) { imageTrancform = ImageService.Instance.LoadCompiledResource("no_profile_image.png"); } else if (imageUrl.Contains("d-cover.jpg")) { imageTrancform = ImageService.Instance.LoadCompiledResource("Cover_image.jpg"); } else if (imageUrl.Contains("http")) { if (!String.IsNullOrEmpty(imageUrl) && (imageUrl.Contains("http") || imageUrl.Contains("file://") || imageUrl.Split('/').Count() > 1)) { imageTrancform = ImageService.Instance.LoadUrl(imageUrl); } else if (!String.IsNullOrEmpty(imageUrl)) { imageTrancform = ImageService.Instance.LoadCompiledResource(imageUrl); } else { imageTrancform = ImageService.Instance.LoadCompiledResource(imagePlaceholder); } } else { var file = Android.Net.Uri.FromFile(new Java.IO.File(imageUrl)); imageTrancform = ImageService.Instance.LoadFile(file.Path); } imageTrancform.TransformPlaceholders(true).Retry(3, 5000).Error(OnError); imageTrancform.DownSampleMode(InterpolationMode.Default); imageTrancform.BitmapOptimizations(true); if (downSample) { imageTrancform.Success((information, result) => { if (information.OriginalHeight > 1000 || information.OriginalWidth > 1000) { imageTrancform.DownSample(250, 250); // imageTrancform.DownSampleInDip(200, 200, false); } else if (information.OriginalHeight > 300 && information.OriginalWidth > 300) { imageTrancform.DownSampleInDip(150, 150, false); // imageTrancform.DownSample(200, 200); } else if (information.OriginalHeight > 200 && information.OriginalWidth > 200) { imageTrancform.DownSample(100, 100); } else if (information.OriginalHeight > 100 && information.OriginalWidth > 100) { imageTrancform.DownSample(40, 40); } else { imageTrancform.DownSample(25, 25); } if (transform == 2) { imageTrancform.Transform(new RoundedTransformation(10)); } }); } if (transform == 1) { imageTrancform.Transform(new CircleTransformation(transformRadius, "#ffffff")); } if (transform == 2) { imageTrancform.Transform(new RoundedTransformation(10)); } if (transform == 3) { imageTrancform.Transform(new RoundedTransformation(10, 2, 2, 10, "#ffffff")); } if (transform == 4) { imageTrancform.Transform(new CircleTransformation(5, Settings.MainColor)); } if (transform == 5) { imageTrancform.Transform(new RoundedTransformation(30)); } imageTrancform.LoadingPlaceholder(imagePlaceholder, ImageSource.CompiledResource); imageTrancform.ErrorPlaceholder(imagePlaceholder, ImageSource.CompiledResource); imageTrancform.Into(imageview); } catch (Exception exception) { Crashes.TrackError(exception); } }