When uploading an image in Android to the server (C #) it generates an error converting the image to byte Array, this happens with some images which is very strange because this error is not always generated, or either depending on the image that is uploaded the image is converted correctly or not.
The code for this conversion on Android is as follows:
ByteArrayOutputStream stream = new ByteArrayOutputStream();
bitmapPhoto.compress(Bitmap.CompressFormat.JPEG, 50, stream);
final byte[] img_byte = stream.toByteArray();
final String imageString = Base64.encodeToString(img_byte, Base64.DEFAULT);
On receiving in C # I make the following conversion into the string, generating a byte Array and then for MemoryStream.
byte[] novaFoto = Convert.FromBase64String(NovaFoto.FotoString);
using (MemoryStream stream = new MemoryStream(novaFoto))
{
Image image = Image.FromStream(stream);
}
Depending on the image, the error appears in Convert.FromBase64String or Image.FromStream.
Can anyone help me with this ?? If you have another way of sending that facilitates and can indicate.