VB有什么办法能直接读出缓冲区中的图片信息(不采用向硬盘写文件再打开的方法)

kytsxy 2008-07-14 09:35:12
我用WINSOCK从服务器把"1.JPG"发送到客户端(二进制文件),客户端Getdata后,有什么办法能直接读出缓冲区中的图片信息(不采用向硬盘写文件再打开的方法)? 听说有什么内存流? 希望众高手帮帮我! 有代码更好!
...全文
90 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
fj182 2008-07-14
  • 打赏
  • 举报
回复
网上转的,非本人原创。


Private Declare Function CreateStreamOnHGlobal Lib "ole32" (ByVal hGlobal As Long, ByVal fDeleteOnRelease As Long, ppstm As Any) As Long
Private Declare Function OleLoadPicture Lib "olepro32" (pStream As Any, ByVal lSize As Long, ByVal fRunmode As Long, riid As Any, ppvObj As Any) As Long
Private Declare Function CLSIDFromString Lib "ole32" (ByVal lpsz As Any, pclsid As Any) As Long
Private Declare Function GlobalAlloc Lib "kernel32" (ByVal uFlags As Long, ByVal dwBytes As Long) As Long
Private Declare Function GlobalLock Lib "kernel32" (ByVal hMem As Long) As Long
Private Declare Function GlobalUnlock Lib "kernel32" (ByVal hMem As Long) As Long
Private Declare Sub MoveMemory Lib "kernel32" Alias "RtlMoveMemory" (pDest As Any, pSource As Any, ByVal dwLength As Long)

Public Function PictureFromByteStream(b() As Byte) As IPicture

Dim hMem As Long
Dim lpMem As Long
Dim LowerBound As Long
Dim ByteCount As Long
Dim IID_IPicture(15)
Dim istm As stdole.IUnknown

LowerBound = LBound(b)
ByteCount = UBound(b) - LowerBound + 1

hMem = GlobalAlloc(&H2, ByteCount)

If hMem <> 0 Then

lpMem = GlobalLock(hMem)

If lpMem <> 0 Then

MoveMemory ByVal lpMem, b(LowerBound), ByteCount

GlobalUnlock hMem

If CreateStreamOnHGlobal(hMem, 1, istm) = 0 Then

If CLSIDFromString(StrPtr("{7BF80980-BF32-101A-8BBB-00AA00300CAB}"), IID_IPicture(0)) = 0 Then

OleLoadPicture ByVal ObjPtr(istm), ByteCount, 0, IID_IPicture(0), PictureFromByteStream

End If

End If

End If

End If

End Function

1,486

社区成员

发帖
与我相关
我的任务
社区描述
VB API
社区管理员
  • API
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧