如何将 bytearray 转换为 img 标签?

Posted

技术标签:

【中文标题】如何将 bytearray 转换为 img 标签?【英文标题】:How to convert bytearray to img tag? 【发布时间】:2012-12-06 10:30:14 【问题描述】:

我有一个返回 png 图像字节数组的服务,我想在我的 jsp 页面上呈现它。 我正在调用 ajax 来获取图像。

$.ajax(
            type: "GET",
            cache: false,
            async: false,
            url: '<spring:url value="/service/org/flk/2"/>',
            success: function(msg) 

【问题讨论】:

看到这个***.com/questions/4564119/… 【参考方案1】:

您需要流式传输 base64 编码数据作为响应,然后您可以这样做

$("#someDivId").html('<img src="data:image/png;base64,'+response + '"/>');

其中response 是base64 编码的图像数据

【讨论】:

我的服务返回 bytearray ,你的意思是分配我从服务获得的响应以将其附加到上面的字符串

以上是关于如何将 bytearray 转换为 img 标签?的主要内容,如果未能解决你的问题,请参考以下文章