Send an image from Android to an ASP.NET Web Service

后端 未结 1 1896
无人及你
无人及你 2021-02-04 20:50

I\'m developing an Android App that should send an image to my ASP.NET Web Service where the image will be saved as a file. I\'ve seen a couple of ways to do this and I went for

相关标签:
1条回答
  • 2021-02-04 21:05

    Seems like there is something iffy with your conversion from string to image. Also you are not disposing your stream which will leak memory.

    Try this instead:

    private Image Base64ToImage(string base64String)
        {
            // Convert Base64 String to byte[]
            byte[] imageBytes = Convert.FromBase64String(base64String);
            using (var ms = new MemoryStream(imageBytes, 0,
                                             imageBytes.Length))
            {
                // Convert byte[] to Image
                ms.Write(imageBytes, 0, imageBytes.Length);
                Image image = Image.FromStream(ms, true);
                return image;
            }
        }
    
    0 讨论(0)
提交回复
热议问题