2010. 6. 25. 17:33
출처
http://www.freevbcode.com/ShowCode.asp?ID=893
http://www.motobit.com/tips/detpg_Base64/

ASP 에서 Base64로 encoding 된 이미지 데이터를 동적으로 출력하는 코드

Test.asp
<%
Session("contentType") = "image/jpg"
Session("ImageBytes") = Base64ToBSTR(base64String)
%>

<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<img src='SesProxy.asp' width='300' height='300'>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>

<%
Function Base64ToBSTR(strBase64)
    Dim Byte1, Byte2, Byte3, Byte4
    Dim Data
    Dim iterator
    Const CharMap = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"

    For iterator = 0 To Len(strBase64) - 1 Step 4
        Byte1 = InStr(CharMap, Mid(strBase64, iterator + 1, 1)) - 1
        Byte2 = InStr(CharMap, Mid(strBase64, iterator + 2, 1)) - 1
        Byte3 = InStr(CharMap, Mid(strBase64, iterator + 3, 1)) - 1
        Byte4 = InStr(CharMap, Mid(strBase64, iterator + 4, 1)) - 1          
        Data = Data & ChrB(Byte1 * 4 + Byte2 \ 16)
        If Byte3 >= 0 Then
            Data = Data & ChrB((Byte2 And 15) * 16 + Byte3 \ 4)
        Else
            Data = Data & ChrB((iterator * 3 \ 4 + 1) = (Byte2 And 15) * 16)
        End If

        If Byte4 >= 0 Then
            Data = Data & ChrB((Byte3 And 3) * 64 + Byte4)
        End If
    Next
    Base64ToBSTR = Data  
End Function
%>

SesProxy.asp
<%
    response.Expires = 0
    response.Buffer  = True
    response.Clear

    response.contentType = Session("contentType")
    response.BinaryWrite Session("ImageBytes")
    response.End
%>

'VBS' 카테고리의 다른 글

[VBS] - MSSOAP 을 사용한 Low level Soap 구현  (0) 2010.06.25
Posted by 짱가쟁이