【问题标题】:Converting base64 to image is giving bitmap data将base64转换为图像是给出位图数据
【发布时间】:2021-07-12 06:10:07
【问题描述】:

我正在尝试将 base64 转换为图像并将图像数据传递给 jquery。在数据表中显示时它不显示图像。因为 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;
    }

这是我的 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">';
    }
 },   

但是图像没有显示在屏幕上,因为我正在从 base64 获取位图到图像转换。请帮帮我。

【问题讨论】:

标签: c# jquery asp.net


【解决方案1】:

您可以使用下面的 HTML sn-p 从图像的 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"/>

【讨论】:

    猜你喜欢
    • 2017-04-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多