简体   繁体   中英

Converting base64 to image is giving bitmap data

Iam trying to convert base64 to image and passing image data to jquery.while dislaying in data table it is not displaying image. because to jQuery image is not going

 public Image Base64StringToImage(string base64String)
    {
        byte[] imageBytes = Convert.FromBase64String(base64String);
        MemoryStream ms = new MemoryStream(imageBytes, 0, imageBytes.Length);

        ms.Write(imageBytes, 0, imageBytes.Length);
        var image = System.Drawing.Image.FromStream(ms);
        return image;
    }

this is my base 64 to image conversion.the following is my jquery.

  { 'data': 'EmpPhoto',
  "render": function (Data, type, row, meta) {
  var imgsrc = 'data:image/png;base64,' + Data;
  return '<img src="/media/' + imgsrc + '" height="100px" width="100px">';
    }
 },   

But image is not displaying in screen because i am getting bitmap from base64 to image conversion.please help me out.

You can use the below HTML snippet to render an image from the base64 string of an image.

<!-- jpeg encoded base64 image string -->
<img src"data:image/jpeg;base64,jpeg_image_base64_encoded_string"/>

<!-- png encoded base64 image string -->
<img src"data:image/png;base64,png_image_base64_encoded_string"/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM