Convert an image to base64 and vice versa

后端 未结 2 879
时光取名叫无心
时光取名叫无心 2021-01-18 07:23

I want to convert an image to base64 and back to image again. Here is the code which i tried so far and the error also. Any suggestions please?

public void Ba         


        
2条回答
  •  情书的邮戳
    2021-01-18 08:10

    The MemoryStream.Read Method reads bytes from the MemoryStream into the specified byte array.

    If you want to write the byte array to the MemoryStream, use the MemoryStream.Write Method:

    ms.Write(imageBytes, 0, imageBytes.Length);
    ms.Seek(0, SeekOrigin.Begin);
    

    Alternatively, you can simply wrap the byte array in a MemoryStream:

    MemoryStream ms = new MemoryStream(imageBytes);
    

提交回复
热议问题