There are various ways of compressing images in Xamarin forms e.g via Nuget packages such as:
- Xam.Plugin.Media – setting the compression quality
- Xamarin.FFimageLoading.Forms – using downsampling feature.
However, if you still require greater compression, then its time to get your hands a little dirty and dive into platform specific implementation (via dependency injection) as unfortunately, image compression is not a feature that is out-of-the box in Xamarin forms.
Firstly, from your Netstardard project, add an IImageCompressionService interface class as shown below:
Thereafter, add the image compression implementation in the ios project and android project as shown below:
iOS implementation
Android implementation
One thing to note from the above implementation. The compressed image will be stored as a new file. If you do not required the original image, you can simply delete it to optimize on storage.