Introduction
Xamarin.Forms code runs on multiple platforms, each of which has its own filesystem. This means that reading and writing files are most easily done using the native file APIs on each platform. Alternatively, embedded resources are a simpler solution to distribute data files with an app.
Tint Image
TintImage is used for changing image color at runtime with the help of effects, you can achieve this with custom render also. Tint image color is mainly used to reduce the usage of the images.
Prerequisites
- Visual Studio 2017 or later (Windows or Mac)
Setting up a Xamarin.Forms Project
Start by creating a new Xamarin.Forms project. You wíll learn more by going through the steps yourself.
Create a new or existing Xamarin forms (.Net standard) Project with Android and iOS Platform.

Create TintImage
Now, Create a TintImage class inherited from RoutingEffect for changing image color.
TintImage.cs
- public class TintImage: RoutingEffect
- {
- public Color TintColor { get; private set; }
- public TintImage(Color color) : base($"MyCompany.{nameof(TintImage)}")
- {
- TintColor = color;
- }
- }
Android Implementation
Here, implement platform effects for TintImage at runtime.
TintImageImpl.cs
- [assembly: ExportEffect(typeof(TintImageImpl), nameof(XamarinStudy.Common.Controls.TintImage))]
- namespace XamarinStudy.Droid.Effects
- {
- public class TintImageImpl: PlatformEffect
- {
- protected override void OnAttached()
- {
- try
- {
- var effect = (XamarinStudy.Common.Controls.TintImage)Element.Effects.FirstOrDefault(e => e is XamarinStudy.Common.Controls.TintImage);
- if (effect == null || !(Control is ImageView image))
- return;
- var filter = new PorterDuffColorFilter(effect.TintColor.ToAndroid(), PorterDuff.Mode.SrcIn);
- image.SetColorFilter(filter);
- }
- catch (Exception ex)
- {
- }
- }
- protected override void OnDetached() { }
- }
- }
iOS Implementation
Here, implement platform effects for TintImage at runtime.
TintImageImpl.cs


Join the conversation! Your thoughts help the community grow.