如何把base64编码转换回图片=bbs整理出来

图片base64编码很长,超过10000个字符,我把该编码赋值给变量s,然后用下面的代码进行转换
Set oStream = Createobject("ADODB.Stream")
With oStream
    .Type = 1
    .Mode = 3
    .Open
End With
Set oDoc = CreateObject("Msxml2.DOMDocument")
With oDoc
    .loadXML "<root/>"
    .documentElement.DataType = "bin.base64"
    .documentElement.text = s
    oStream.Write .DocumentElement.NodeTypedValue
End With
Set oDoc = Nothing
oStream.Position=0
Response.ContentType="image/gif"
Response.BinaryWrite oStream.read()
Set oStream = Noting


运行结果如下:
msxml3.dll 错误 '80004005' 
分析 '<?xml version="1.0" encoding="UTF-8" ?> <response> <head> <code>0</code> <message>成功</message> </head> <body> <zp>/9j/4AAQSk...' 为 bin.base64 数据类型时发生错误。

请问应如何才能显示上述编码的图片?


Visual Basic code
?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<%@ codepage= "65001"  %>
<%
 
Dim  s
 
s =  "R0lGODlhKAAoAPcAAP///xa97BamyQC36gC36QC05QCv3QCfxQCfxPr5+vPy8/Lx8vHw8e7t"
s = s &  "7uvq6+rp6ujn6OXk5eTj5OLh4t/e393c3dzb3Nva29rZ2tnY2dfW19LR0tDP0M/Oz87NzszL"
s = s &  "zMvKy7y8vbm7vbm8vra7vrO7v7W7vrq8vbC7wKy7wbG7v7W8v6q7wZm5w5q6xKK7w6W7wqi7"
s = s &  "wam5vrC8wK+7vwC26QC25wC15gCz5ACz4wOz4wOy4QS15gq25Qqz4Q214g625BG86xC14hKv"
s = s &  "2RW97BOy3Ra86xW14Ra86Ra76Ra65xa55Ru34yO02ya44CrD7Sq33iq12yq02Syw1C+02C+z"
s = s &  "1zK43TG33DG12TWw0Tez1T621z+32T2z00C42UC11US42Eu41kqyzlO41FW20VW1z1q51Fu4"
s = s &  "0lu30F+602W0ymq4zWq2y2m1ym260HG5zne6zXe3yXu5yoC6y4K6yn61xIG4x4O5yYG3xoO4"
s = s &  "x4i6yYm5x466x5G7x5O4w5i7xZu5wp65waC7w6K5wKW5v627vwCy4QCx4ACw3gCu3ACt2wCs"
s = s &  "2QCr2ACr1gCq1QCp0wCn0ACmzwClzgCkzACjywCiyACgxgKr2AKgxgOt2gSr1gWozwmnzgmj"
s = s &  "yQyy3Qur1AuhxBCnzRGlyBOr0Ra65Ra44xa34hOjxRa24Ba13xa03Raz3Bay2xax2Raw1xav"
s = s &  "1Bau0xat0hWmyReu1has0BarzxaqzRapzBaoyxanyhmqzRmmyRilxhqrzxyy2RuozB6w1x2r"
s = s &  "zyCu0yGoySWy1yKmxSmv0imryyquzi6y1SypxjGuzTawzzu01Dyy0TywzjuvzD2sx0Kqw0et"
s = s &  "xUuvyE+10EutxFCwyFqzylmuw2K1y2O2zGOyx2GuwWWyxWq1yWexw2uzxmuwwW6zxXC1x26y"
s = s &  "w3Cyw4a2woq1wI+2wI61v6K5v/7+/vz8/Pr6+vn5+fb29vX19fT09O7u7u3t7enp6efn5+bm"
s = s &  "5uLi4uHh4eDg4N7e3tXV1dPT09HR0c3NzSwAAAAAKAAoAAAI/wCfEAlAsKDBgwgTKiTyJMiA"
s = s &  "hxAjSpxIseLDIAEIaNzIsSMBJ2bcpHHisSTHAEZqqFzJkqWVOTMqSNg3Aw6TljhZGkmZk2UP"
s = s &  "OB4exKM37527CTO89MRpBImNp1Cj2gDSx0K9EIL08EnRb968EGCkin2KJMnYqHQqYOhzhcdT"
s = s &  "IFz4aGCwAsrZqEmS3NjLt++YDBne8OjLN8wKe396EF6cREmBx5AhC2FRAU7kywXOVLhwBvNl"
s = s &  "JY49FyBz4cUP0Y/HYIDH4gjqAqBxyJ4tW8cfC2Ro68axBUU8APvQ7KathFSO48iPRwHxIUpy"
s = s &  "5Dqw3AnRAAAAeDB8PE9Oaomh7+C/o/+xEEJK+B1N0LjwUM+6+35bwstf4l3+9zsO7O2hIuXL"
s = s &  "GhcjVKCAewRCIId94C1RyiEMNnhIES/AAwAE/3zQDz4KzGOBP/9wgIED7VgHTwyeOOhgKaYg"
s = s &  "ouKKiFRhQogE3jMCH2g0U4UW1eRhAj7WeVAFiyyakiKQiFSTAYENhGAHMUQi4osdR15QhidN"
s = s &  "moKKAVhmacA2+riXTwpdaCkmlnZAcE8cxIxpACpXjskGj8C14IuaYibzDwN+hDkmKqkk4uef"
s = s &  "ibCRDzv2tDAEoIgCCswI2JWRaCKpqKLIpJQqog0F7JwwRaWccurMBu8Uok2niqgiaadiaLBA"
s = s &  "C5mQSioe9bj/U0IbpKqyyiK45rqIMSqEOouuwOqaRQfsyPpNsIuswgojzDbLyCeAMECBH8I4"
s = s &  "ay2zl/hRDzvvoKDGtYywwkoj5JZLLjn4sIMPCXUwo4m55j7jDzvssIYNvOSy0ooj/PbLr7zt"
s = s &  "tJOAPR34YYy//eIBQcALBCIGwvy24sojFFdM8SeEyBNwwBGQAI3Fj4xSCDwBP3DOMiBT7MrE"
s = s &  "KVPMTQUbl0xDMBYv48HG+oTTS8uuvALJz0ADrYsK8LhjtNEUjBP0NRoczQ81mwQN9CuwRGL1"
s = s &  "1Vh7c8E7XHPNwCCcXM2NBV2HcAzWWMMSiyRst+12KOtAAM/c8MRDwi9tl0PB3AwQ2sKJ227H"
s = s &  "QsskhBdu+CTRdEB33SIMU7g5e8MjQR2HG05LLZRkrvnmmZejQTygK2DCLpqDYwHo/VjD+ea1"
s = s &  "YL46552kc4E88tBDSCeaZ6OBPAyUQPrrlNRiSyXEF2988bysY8EC+Jxj/DT+LCABOscfb8st"
s = s &  "1WdfSTEyZMCBNMYrAwIDG1ijPfG34GLJ+uy37z4v4mSDSfunqOCADKe47z4uuRzg//8ADKAA"
s = s &  "/6cOfnRjgADMhSgQwMAGOvCBEGygNNQBigg6UBTIkIUANsjBDnrwgxtUxjRA2EFZICMg"
s = s &  "ADs="
 
 
Response.ContentType =  "image/gif"
With  Server.CreateObject( "MSXML2.DOMDocument" ).createElement( "e" )
     .dataType =  "bin.base64"
     .text = s
     Response.BinaryWirte .nodeTypedValue
End  With
 
%>

大图片的话,把 base64 编码结果截断,  分多次解码并 BinaryWrite 出去就行

注意每次截取的字符长度应该是 4 的倍数


-------------------------------

dom element 的 .nodeTypedValue 就是 byte 数组, 直接 binaryWrite 出去就可以

不需要放到 stream 中,再读出


原文网址:http://bbs.csdn.net/topics/360130278


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值