VB6从数据库或服务器上拿到base64编码的字符串(图片数据),如何解码并保存在指定的文件夹里头,求大神帮忙.
PrivateSubShowPicture(msgAsString)OnErrorGoToErrHandDimstrS()AsStringDimbyDataAsStrin...
Private Sub ShowPicture(msg As String)
On Error GoTo ErrHand
Dim strS() As String
Dim byData As String
Dim pic() As Byte
Dim c1 As New Class1
''向服务器发送接收图片请求 bbb为请求ID
Dim objHTTP As Object
Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")
objHTTP.setTimeouts 20000, 20000, 20000, 20000
objHTTP.open "GET", WsServer & "servlet/DoDownloadBackground?id=" & msg
objHTTP.send
lmsg "msg" & msg
byData = objHTTP.responseText '接收字符串
'Text5.Text = c1.Base64Decode(Text3.Text)
pic = c1.Base64Decode(byData) 'base64解码
'pic = c2.DecodeBase64StringToFile(byData, 0)
'接收文件'
Open "D:" & "\" & msg & ".jpg" For Binary As #1
Put #1, , pic
Close #1
ErrHand:
'Me.SetFocus
lmsg "ShowMsg:::: Error: " & err.Description
End Sub
这里能保存但是不可以打开图片查看, 展开
On Error GoTo ErrHand
Dim strS() As String
Dim byData As String
Dim pic() As Byte
Dim c1 As New Class1
''向服务器发送接收图片请求 bbb为请求ID
Dim objHTTP As Object
Set objHTTP = CreateObject("MSXML2.ServerXMLHTTP")
objHTTP.setTimeouts 20000, 20000, 20000, 20000
objHTTP.open "GET", WsServer & "servlet/DoDownloadBackground?id=" & msg
objHTTP.send
lmsg "msg" & msg
byData = objHTTP.responseText '接收字符串
'Text5.Text = c1.Base64Decode(Text3.Text)
pic = c1.Base64Decode(byData) 'base64解码
'pic = c2.DecodeBase64StringToFile(byData, 0)
'接收文件'
Open "D:" & "\" & msg & ".jpg" For Binary As #1
Put #1, , pic
Close #1
ErrHand:
'Me.SetFocus
lmsg "ShowMsg:::: Error: " & err.Description
End Sub
这里能保存但是不可以打开图片查看, 展开
1个回答
展开全部
Private Declare Function CreateStreamOnHGlobal Lib "ole32.dll" ( _
ByVal hGlobal As Long, _
ByVal fDeleteOnRelease As Long, _
lpIStream As IUnknown) As Long
Private Declare Function OleLoadPicture Lib "oleaut32.dll" ( _
ByVal lpStream As IUnknown, _
ByVal lSize As Long, _
ByVal fRunmode As Long, _
riid As Any, _
lpIPicture As IPicture) As Long
Function ByteToPict(PictureData() As Byte) As StdPicture 'Byte转图片
Dim IID_IPicture(3) As Long
Dim oPicture As IPicture
Dim nResult As Long
Dim oStream As IUnknown
Dim hGlobal As Long
IID_IPicture(0) = &H7BF80980
IID_IPicture(1) = &H101ABF32
IID_IPicture(2) = &HAA00BB8B
IID_IPicture(3) = &HAB0C3000
Call CreateStreamOnHGlobal(VarPtr(PictureData(LBound(PictureData))), 0, oStream)
nResult = OleLoadPicture(oStream, 0, 0, IID_IPicture(0), oPicture)
If nResult = 0 Then
Set ByteToPict = oPicture
End If
End Function
先把byte转为StdPicture再进行SavePicture
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询