如何将Base64转换为图像

时间:2014-09-10 06:47:55

标签: javascript jquery sql asp.net

我正在尝试从数据库中显示图像。我已将数据库映像转换为base 64格式。我正在使用JavaScript进行转换。但它不是图像格式。我的代码如下:

var che = btoa(data.d.ItemImage1);
$('#imgUpload').attr('src', "data:image/png;base64," + che);

警告此时,格式如下,但无法显示图像。

MTAwLDk3LDExNiw5Nyw1OCwxMDUsMTA5LDk3LDEwMywxMDEsNDcsMTA2LDExMiwxMDEsMTAzLDU5LDk4LDk3LDExNSwxMDEsNTQsNTIsNDQsNDcsNTcsMTA2LDQ3LDUyLDY1LDY1LDgxLDgzLDEwNyw5MCw3NCw4MiwxMDMsNjUsNjYsNjUsMTAzLDY5LDY1LDg5LDY1LDY2LDEwMyw2NSw2NSw2OCw0Nyw1NSwxMDMsNjUsNzksODEsODcsODIsMTE4LDg5LDEwOSw4NSw2NSw5MCw2NSw2NSw2NSw2NSw2NSw2NSw2Niw0Nyw0Myw2OSw4Myw2Nyw2OSw4Niw1Miw5Nyw4Nyw4OSw2NSw2NSw2OSw0OSw3OCw2NSw2NywxMTEsNjUsNjUsNjUsNjUsNzMsNjUsNjUsOTksNjYsNzcsMTAzLDY1LDY3LDY1LDY1LDY1LDY1LDcwLDY1LDY1LDY1LDY1LDcxLDczLDY2LDc5LDExOSw2NSw2Nyw2NSw2NSw2NSw2NSw2NiwxMTksNjUsNjUsNjUsNzIsOTAsNzIsODIsMTAzLDY1LDY4LDY1LDY1LDY1LDY1LDY1LDgxLDY1LDY5LDY1LDY1LDY2LDcyLDgzLDgxLDY1LDY4LDY1LDY1LDY1LDY1LDY1LDgxLDY1LDQ3LDY1LDY1LDY3LDk5LDExMCw4MSw2NSw2Niw2NSw2NSw2NSw2NSw2OCwxMDMsNjUsNjUsNjUsNjUsNjgsMTEzLDcyLDY1LDY1LDcyLDY1LDY1LDY1LDcyLDk4LDEwMyw2NSw2NSw2NSw2NSw2Nyw3Miw5Nyw4MSw2NSw2OSw2NSw2NSw2NSw2NSw2NSw4MSw2NSw2NSw2NSw3Miw0OCw2NSw2NSw2NSw2OCwxMTAsNzcsMTA2LDY1LDExOSw3OSw4NCwxMTEsMTE5LDc3LDEyMiwxMTEsMTIwLDc3LDEwNSw2NSwxMjAsNzcsMTIyLDExMSw0OCw3OSw2OCwxMTEsMTIyLDc4LDgxLDY2LDY4LDk4LDUxLDc0LDEwNSw5Nyw4OCw3Nw== 

2 个答案:

答案 0 :(得分:0)

为您的案例尝试以下

$('#imgUpload').attr('src', String.fromCharCode.apply(null, data.d.ItemImage1));

答案 1 :(得分:0)

使用此:

$('#imgPhoto')。attr('src',“data:image / jpeg; base64,”+ imageData); 工作正常。我们正在使用它。 检查imageData值(在您的情况下是data.d.ItemImage1)。使用警告检查值。