private void Transform() { ImageViewAsync imageAsync; if ((imageAsync = CastImageViewToAsync()) == null) { return; } if (!_strem.IsNull()) { ImageService.Instance .LoadStream(cancelationToken => System.Threading.Tasks.Task.Factory.StartNew( () => { cancelationToken.ThrowIfCancellationRequested(); var streamClone = new MemoryStream(); if (_strem?.CanSeek ?? false) { _strem?.Seek(0, SeekOrigin.Begin); } _strem?.CopyTo(streamClone); if (streamClone?.CanSeek ?? false) { streamClone?.Seek(0, SeekOrigin.Begin); } return(streamClone as Stream); }, cancelationToken)) .Transform(new CircleTransformation()) .Finish(obj => SetImageColorFilter(_imageColor)) .Into(imageAsync); } else if (!Url.IsNullOrWhiteSpace()) { ImageService.Instance .LoadUrl(Url) .Transform(new CircleTransformation()) .Finish(obj => SetImageColorFilter(_imageColor)) .Into(imageAsync); } else if (DrawableId > 0) { ImageService.Instance .LoadCompiledResource(DrawableId.ToString()) .Transform(new CircleTransformation()) .Finish(obj => SetImageColorFilter(_imageColor)) .Into(imageAsync); } }
public void SetBackgroundColor(string color, float?radiusAspect = null, string borderColor = null, float?borderWidth = null, RadiusType type = RadiusType.Static, string selectedColorView = "") { if (WrappedObject == null) { ExceptionLogger.RaiseNonFatalException( new ExceptionWithCustomStack( WrappedObjectIsNull, Environment.StackTrace)); return; } if (string.IsNullOrEmpty(color)) { ExceptionLogger.RaiseNonFatalException( new ExceptionWithCustomStack( EmptyColorError, Environment.StackTrace)); color = TransparentColor; } if (selectedColorView.IsNullOrWhiteSpace()) { ColorOriginalView = color; ColorOriginalV2View = ColorOriginalView; } else { ColorOriginalV2View = selectedColorView; } BorderColor = borderColor; BorderWidth = borderWidth; RadiusValueType = type; RadiusAspect = radiusAspect; if (RadiusAspect != null && WrappedObject is ImageView) { WrappedObject = (FFImageLoading.Views.ImageViewAsync)WrappedObject; if (radiusAspect == null) { return; } var b = new FFImageLoading.Transformations.CornersTransformation((double)radiusAspect, FFImageLoading.Transformations.CornerTransformType.AllRounded, 0, 0); if (!Url.IsNullOrWhiteSpace()) { var a = FFImageLoading.ImageService.Instance .LoadUrl(Url) .Transform(new List <FFImageLoading.Work.ITransformation>() { b }); FFImageLoading.TaskParameterPlatformExtensions.Into(a, WrappedObject as FFImageLoading.Views.ImageViewAsync); } else if (DrawableId > 0) { var a = FFImageLoading.ImageService.Instance .LoadCompiledResource(DrawableId.ToString()) .Transform(b); FFImageLoading.TaskParameterPlatformExtensions.Into(a, WrappedObject as FFImageLoading.Views.ImageViewAsync); } } else if (RadiusAspect != null && borderWidth != null) { if (string.IsNullOrEmpty(color)) { ExceptionLogger.RaiseNonFatalException( new ExceptionWithCustomStack( EmptyBorderColorError, Environment.StackTrace)); borderColor = TransparentColor; } switch (type) { case RadiusType.Aspect: InvokeWithMeasuredHeight(height => SetRoundView(WrappedObject, ColorOriginalV2View.ToColor(), height * RadiusAspect.Value, borderColor.ToColor(), borderWidth.Value)); break; case RadiusType.Static: SetRoundView(WrappedObject, ColorOriginalV2View.ToColor(), RadiusAspect.Value.Iphone6PointsToDevicePixels(), borderColor.ToColor(), borderWidth.Value); break; } } else if (RadiusAspect != null) { switch (type) { case RadiusType.Aspect: InvokeWithMeasuredHeight(height => SetRoundView(WrappedObject, ColorOriginalV2View.ToColor(), height * RadiusAspect.Value)); break; case RadiusType.Static: SetRoundView(WrappedObject, ColorOriginalV2View.ToColor(), RadiusAspect.Value.Iphone6PointsToDevicePixels()); break; } } else { switch (type) { case RadiusType.Aspect: if (!borderColor.IsNull()) { InvokeWithMeasuredHeight(height => { if (borderWidth != null) { SetRoundView(WrappedObject, ColorOriginalV2View.ToColor(), height * 0.5f, borderColor?.ToColor(), borderWidth.Value); } }); } else { InvokeWithMeasuredHeight(height => SetRoundView(WrappedObject, ColorOriginalV2View.ToColor(), height * 0.5f)); } break; default: AppTools.CurrentActivity?.RunOnUiThread(() => { WrappedObject.SetBackgroundColor(ColorOriginalV2View.ToColor()); }); break; } } }