'Custom Image Sizing Mode for ImageButton in xamarin.forms

Situation

I am currently exploring android development on xamarin and therefor decided to develop a small game.

Within the game, I have an ImageButton to access some menus. For instance the level up screen. I made some low res image for the image button:

enter image description here

Issue

Now, if I use this in the image button, the image gets scaled up and therefore looks Blurry:
enter image description here

I guess, the reason being is bi-linear image sizing.

The proper implementation for my specific case would be sizing with nearest neighbor, as it preserves the low pixel look:

enter image description here

Question

How would I go about changing this? I have found code for WPF winforms but realized that xamarin has different calls...

class ImageButtonWithHardEdgeExpansion : SomeControl
{
    public InterpolationMode InterpolationMode { get; set; }

    protected override void OnPaint(PaintEventArgs paintEventArgs)
    {
        paintEventArgs.Graphics.InterpolationMode = InterpolationMode;
        base.OnPaint(paintEventArgs);
    }
}

For an intermediate workaround, I can use an external image resizer and store the image in high res... but that defies the purpose for me a little. so I am looking for a more long term solution.



Solution 1:[1]

You can use the padding to do this.

Before padding:

enter image description here

After padding:

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Ethan