My app uploads images to Azure Storage from the camera roll in iOS but they are about 4.7MB and so I want to reduce their size by scaling or compression. I see in MonoTouch there are a few methods on UIImage such as Scale and AsJPEG which I can use. My question is how do I hook up these native methods to my Xamarin.Forms control? I have dabbled with custom renderers but, since I need to pass in parameters, I'm not sure how I can do that with either a BindableProperty or a Command. If I go the DependencyService route, I'm not sure how to use it on an instance of an Image.
How would this be accomplished? I was trying to use the DependencyService approach and implement the interfaces on my own ExtendedImage renderer, but then I got stuck on how I would call the methods from my shared code. Here is where I was going with it:
public class ExtendedImageRenderer : ImageRenderer, IScalableImage, IEncodedImage
{
public ExtendedImageRenderer ()
{
}
public void Scale(float width, float height)
{
base.Control.Image.Scale (new System.Drawing.SizeF { Width = width, Height = height });
}
public Image AsPNGImage()
{
return new Image { Source = ImageSource.FromStream(base.Control.Image.AsPNG().AsStream()) };
}
}