简体   繁体   English

将 base64 转换为图像会给出 bitmap 数据

[英]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.我试图将 base64 转换为图像并将图像数据传递给 jquery。在数据表中显示时,它不显示图像。 because to jQuery image is not going因为到 jQuery 图像不去

 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.这是我的 base 64 到图像转换。以下是我的 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.但是图像没有显示在屏幕上,因为我正在从 base64 获取 bitmap 到图像转换。请帮帮我。

You can use the below HTML snippet to render an image from the base64 string of an image.您可以使用下面的 HTML 片段从图像的 base64 字符串渲染图像。

<!-- 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"/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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