VB6从数据库或服务器上拿到base64编码的字符串(图片数据),如何解码并保存在指定的文件夹里头,求大神帮忙.
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了VB6从数据库或服务器上拿到base64编码的字符串(图片数据),如何解码并保存在指定的文件夹里头,求大神帮忙.相关的知识,希望对你有一定的参考价值。
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
这里能保存但是不可以打开图片查看,
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
以上是关于VB6从数据库或服务器上拿到base64编码的字符串(图片数据),如何解码并保存在指定的文件夹里头,求大神帮忙.的主要内容,如果未能解决你的问题,请参考以下文章