How to send and receive image by json? [closed]

1

I made an app in Xamarin that the person will have to sign and I need to send that image to the server If possible leave the code to accomplish such task

    
asked by anonymous 04.02.2018 / 14:43

2 answers

1

What I have is a stream that I need to send to the server so it stayed like this

 Atendimento_ViewModel.Assinatura = await Pad.GetImageStreamAsync(SignatureImageFormat.Png) as  MemoryStream;
app local
byte[] imageBytes = Assinatura.ToArray();
pedido.Assinatura = Convert.ToBase64String(imageBytes);

Server

byte[] bytes = Convert.FromBase64String(pedido.Assinatura);
MemoryStream stream = new MemoryStream(bytes);
Image Image1 = Image.GetInstance(System.Drawing.Image.FromStream(stream),System.Drawing.Imaging.ImageFormat.Png);

The above code is to get the signature written and be sent to the server, attention if the intention is to send the image in a pdf it should be .pdf

    
06.02.2018 / 17:37
1

Basically, assuming you have the image stored locally, or simply have the byte array of it:

byte[] bytes = System.IO.File.ReadAllBytes(FileName);
String strImage = Convert.ToBase64String(b);

Then you send this to the server, as a string parameter any.

On the server, to do the reverse process:

byte[] bytes = Convert.FromBase64String(strDaImagemRecebida);

Image image;
using (MemoryStream ms = new MemoryStream(bytes))
{
    image = Image.FromStream(ms);
}
    
05.02.2018 / 15:43