An efficient way to Base64 encode a byte array?

前端 未结 8 1794
再見小時候
再見小時候 2020-11-30 07:18

I have a byte[] and I\'m looking for the most efficient way to base64 encode it.

The problem is that the built in .Net method Convert.FromBase64

相关标签:
8条回答
  • 2020-11-30 08:04
    byte[] base64EncodedStringBytes = Encoding.ASCII.GetBytes(Convert.ToBase64String(binaryData))
    
    0 讨论(0)
  • 2020-11-30 08:04

    To retrieve your image from byte to base64 string....

    Model property:

        public byte[] NomineePhoto { get; set; }
    
        public string NomineePhoneInBase64Str 
        {
            get {
                if (NomineePhoto == null)
                    return "";
    
                return $"data:image/png;base64,{Convert.ToBase64String(NomineePhoto)}";
            } 
        }
    

    IN view:

       <img style="height:50px;width:50px" src="@item.NomineePhoneInBase64Str" />
    
    0 讨论(0)
提交回复
热议问题