void SetTint() { if ((Control == null) || (Element == null)) { return; } if (CustomElement.TintColor.Equals(Xamarin.Forms.Color.Transparent)) { //Turn off tinting if (Control.ColorFilter != null) { Control.ClearColorFilter(); } return; } //Apply tint color var colorFilter = new PorterDuffColorFilter(CustomElement.TintColor.ToAndroid(), PorterDuff.Mode.SrcIn); Control.SetColorFilter(colorFilter); }
private void SetTint() { if (Control == null || Element == null) { return; } if (((TintableImage)Element).Tint.Equals(Color.Transparent)) { //Turn off tinting if (Control.ColorFilter != null) { Control.ClearColorFilter(); } return; } //Apply tint color var colorFilter = new PorterDuffColorFilter(((TintableImage)Element).Tint.ToAndroid(), PorterDuff.Mode.SrcIn); Control.SetColorFilter(colorFilter); }
public static Bitmap ToSolidColor(Bitmap sourceBitmap, int r, int g, int b, int a) { var config = sourceBitmap?.GetConfig(); if (config == null) { config = Bitmap.Config.Argb8888; } int width = sourceBitmap.Width; int height = sourceBitmap.Height; Bitmap bitmap = Bitmap.CreateBitmap(width, height, config); using (Canvas canvas = new Canvas(bitmap)) { using (Paint paint = new Paint()) { PorterDuffColorFilter cf = new PorterDuffColorFilter(Color.Argb(a, r, g, b), PorterDuff.Mode.SrcAtop); paint.SetColorFilter(cf); canvas.DrawBitmap(sourceBitmap, 0, 0, paint); return(bitmap); } } }
public DroidContentPageRenderer(Context context) : base(context) { if (context == null) { context = MainActivity.Instance; } var toolbar = (context as MainActivity).FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar); if (toolbar != null) { var color = (Xamarin.Forms.Color)Xamarin.Forms.Application.Current.Resources.MergedDictionaries.ToList()[0]["PrimaryTintColor"]; PorterDuffColorFilter colorFilter = new PorterDuffColorFilter(color.ToAndroid(), PorterDuff.Mode.Multiply); //1. Changing Tint color for the Toolbar icons var menu = toolbar.Menu; if (menu != null && menu.HasVisibleItems) { var i = 0; while (true) { IMenuItem item = null; try { item = menu.GetItem(i++); } catch (Java.Lang.IndexOutOfBoundsException) { break; } item.Icon?.SetColorFilter(colorFilter); } } } }
void SetTint() { if (Control != null && Element != null) { var colorFilter = new PorterDuffColorFilter(((TintedImage)Element).TintColor.ToAndroid(), PorterDuff.Mode.SrcIn); Control.SetColorFilter(colorFilter); } }
protected override void OnAttached() { var effect = Element.Effects.FirstOrDefault(e => e is ImageTint) as ImageTint; control = Control as ImageView; var filter = new PorterDuffColorFilter(effect.tint.ToAndroid(), PorterDuff.Mode.SrcOver); control.SetColorFilter(filter); }
protected override void OnAttached() { var seekBar = Control as SeekBar; var colorFilter = new PorterDuffColorFilter(Xamarin.Forms.Color.Red.ToAndroid(), PorterDuff.Mode.SrcIn); seekBar.ProgressDrawable.SetColorFilter(colorFilter); seekBar.Thumb.SetColorFilter(colorFilter); //seekBar.SetThumb(); //seekBar.SetBackgroundResource(); }
private void SetTint() { if (Control == null || Element == null) { return; } var colorFilter = new PorterDuffColorFilter(((TintedImage)Element).TintColor.ToAndroid(), PorterDuff.Mode.SrcIn); Control.SetColorFilter(colorFilter); }
void SetTint() { if (Control == null || Element == null) { return; } var colorFromResources = ((Xamarin.Forms.Color)App.Current.Resources["ImageTintColor"]).ToAndroid(); var colorFilter = new PorterDuffColorFilter(colorFromResources, PorterDuff.Mode.SrcIn); Control.SetColorFilter(colorFilter); }
private void ApplyTintColor() { var colorFilter = new PorterDuffColorFilter(tintColor, PorterDuff.Mode.SrcIn); if (Control is ImageView) { (Control as ImageView).ClearColorFilter(); (Control as ImageView).SetColorFilter(colorFilter); } else { Control.Background.ClearColorFilter(); Control.Background.SetColorFilter(colorFilter); } }
private void SetTint(TintedImage element) { if (element.TintColor.Equals(Xamarin.Forms.Color.Transparent)) { if (Control.ColorFilter != null) { Control.ClearColorFilter(); } return; } var colorFilter = new PorterDuffColorFilter(element.TintColor.ToAndroid(), PorterDuff.Mode.SrcIn); Control.SetColorFilter(colorFilter); }
void SetBackgroundColor(string mimeType) { var colorFilter = new PorterDuffColorFilter(Color.Gray, PorterDuff.Mode.SrcIn); if (IsImage(mimeType)) { imageHintContainer.Background.SetColorFilter(colorFilter); imageHintContainer.Elevation = 4; imageHintContainer.Invalidate(); } else if (IsText(mimeType)) { textHintContainer.Background.SetColorFilter(colorFilter); textHintContainer.Elevation = 4; textHintContainer.Invalidate(); } }
private void TintPicture() { if (Control == null || Element == null) { return; } var profilePic = Element as ProfilePic; if (profilePic.TintColor == Xamarin.Forms.Color.Transparent) { Control.ClearColorFilter(); } else { var colorFilterToApply = new PorterDuffColorFilter(profilePic.TintColor.ToAndroid(), PorterDuff.Mode.SrcIn); Control.SetColorFilter(colorFilterToApply); } }
protected override void OnAttached() { try { var effect = (FormsTintImageEffect)Element.Effects.FirstOrDefault(e => e is FormsTintImageEffect); if (effect == null || !(Control is ImageView image)) { return; } var filter = new PorterDuffColorFilter(effect.TintColor.ToAndroid(), PorterDuff.Mode.SrcIn); image.SetColorFilter(filter); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine( $"An error occurred when setting the {typeof(TintImageEffect)} effect: {ex.Message}\n{ex.StackTrace}"); } }
private void SetColor() { if (Control == null || !(Element is ColorImage colorImage)) { return; } if (colorImage.Color.Equals(Xamarin.Forms.Color.Transparent)) { if (Control.ColorFilter != null) { Control.ClearColorFilter(); } } else { var colorFilter = new PorterDuffColorFilter(colorImage.Color.ToAndroid(), PorterDuff.Mode.SrcIn); Control.SetColorFilter(colorFilter); } }
void SetColorTint() { if (Control == null || Element == null) { return; } if (((BMImage)Element).TintColor.Equals(Xamarin.Forms.Color.Transparent)) { if (Control.ColorFilter != null) { Control.ClearColorFilter(); } return; } var colorFilter = new PorterDuffColorFilter(((BMImage)Element).TintColor.ToAndroid(), PorterDuff.Mode.SrcIn); Control.SetColorFilter(colorFilter); }
protected override void onDraw(Canvas canvas) { canvas.drawColor(unchecked ((int)0xFFCCCCCC)); canvas.translate(8, 12); foreach (int color in mColors) { ColorFilter filter; if (color == 0) { filter = null; } else { filter = new PorterDuffColorFilter(color, mModes [mModeIndex]); } drawSample(canvas, filter); canvas.translate(0, 55); } }
private void ApplyTintColor() { var tintColor = GetTintColor(); var colorFilter = new PorterDuffColorFilter(tintColor.ToAndroid(), PorterDuff.Mode.SrcIn); if (Control is global::Android.Widget.ImageView) { var control = Control as global::Android.Widget.ImageView; control?.SetColorFilter(colorFilter); } else if (Control is global::Android.Widget.ImageButton) { var control = Control as global::Android.Widget.ImageButton; control?.SetColorFilter(colorFilter); } else if (Control is global::Android.Widget.Button) { var control = Control as global::Android.Widget.Button; control.CompoundDrawableTintMode = PorterDuff.Mode.SrcIn; int[][] states = new int[][] { new int[] { Android.Resource.Attribute.StateEnabled }, new int[] { -Android.Resource.Attribute.StateEnabled }, new int[] { -Android.Resource.Attribute.StateChecked }, new int[] { Android.Resource.Attribute.StateChecked } }; int[] colors = new int[] { tintColor.ToAndroid(), tintColor.ToAndroid(), tintColor.ToAndroid(), tintColor.ToAndroid(), }; control.CompoundDrawableTintList = new Android.Content.Res.ColorStateList(states, colors); } }
private BitmapDescriptor GetCustomBitmapDescriptor(string text) { using (Paint paint = new Paint(PaintFlags.AntiAlias)) { using (Rect bounds = new Rect()) { using (Bitmap baseBitmap = BitmapFactory.DecodeResource(Resources, Resource.Drawable.Pin8)) { Bitmap resultBitmap = Bitmap.CreateBitmap(baseBitmap, 0, 0, baseBitmap.Width - 1, baseBitmap.Height - 1); Paint p = new Paint(); ColorFilter filter = new PorterDuffColorFilter(Android.Graphics.Color.ParseColor(text), PorterDuff.Mode.SrcAtop); p.SetColorFilter(filter); Canvas canvas = new Canvas(resultBitmap); canvas.DrawBitmap(resultBitmap, 0, 0, p); Bitmap scaledImage = Bitmap.CreateScaledBitmap(resultBitmap, 64, 64, false); BitmapDescriptor icon = BitmapDescriptorFactory.FromBitmap(scaledImage); resultBitmap.Recycle(); return(icon); } } } }
protected override MarkerOptions CreateMarker(Pin pin) { var marker = new MarkerOptions(); marker.SetPosition(new LatLng(pin.Position.Latitude, pin.Position.Longitude)); marker.SetTitle(pin.Label); marker.SetSnippet(pin.Address); ColouredMapPin customPin = (ColouredMapPin)pin; var colour = HexColourtoAndroidColour(customPin.Colour); var bmp1 = BitmapFactory.DecodeResource(Context.Resources, Resource.Drawable.pin); var icon = bmp1.Copy(bmp1.GetConfig(), true); Paint paint = new Paint(); ColorFilter filter = new PorterDuffColorFilter(colour, PorterDuff.Mode.SrcIn); paint.SetColorFilter(filter); Canvas canvas = new Canvas(icon); canvas.DrawBitmap(icon, 0, 0, paint); marker.SetIcon(BitmapDescriptorFactory.FromBitmap(icon)); return(marker); }