1
I am developing an application in Xamarin.Forms
that uses the camera of the mobile phone to capture images, however, depending on the client’s mobile the image can reach up to 12MB, this is too much for our server.
During my searches, I discovered that the class Bitmap
of System.Drawing
works only with Windows and not with Xamarin, so I eliminated this possibility.
In some places I discovered I could use the Bitmap
of Xamarin, so I did the following:
using (var ms = new MemoryStream())
{
stream.CopyTo(ms);
ImageBytes = ms.ToArray();
Bitmap imagemBitmap = BitmapFactory.DecodeByteArray(ImageBytes, 0, ImageBytes.Length);
imagemBitmap.Compress(Bitmap.CompressFormat.Jpeg, 5, ms);
bytesCompactados = ms.ToArray();
}
However, unfortunately, regardless of the quality I put among the parentheses of Compress
, be it 0 or 100, it does not interfere in anything and ends up increasing the size of the image to decrease.
To decrease the size, you can change the resolution and/or compress the image quality.
Does anyone know how to fix this, or maybe they have an idea of a better way to do it? Thanks in advance
It worked, thank you very much!!
– Renan Mussatto
@Renanmussatto Good bro, do not forget to mark as accepted answer
– Guilherme Nimer