直接显示二进制图片

Option Explicit
Private Type GUID
Data1 As Long
Data2 As Integer
Data3 As Integer
Data4(7) As Byte
End Type
Private Declare Function CreateStreamOnHGlobal Lib “ole32.dll” (ByRef hGlobal As Any, ByVal fDeleteOnResume As Long, ByRef ppstr As Any) As Long
Private Declare Function OleLoadPicture Lib “olepro32.dll” (ByVal lpStream As IUnknown, ByVal lSize As Long, ByVal fRunMode As Long, ByRef riid As GUID, ByRef lplpObj As Any) As Long
Private Declare Function CLSIDFromString Lib “ole32.dll” (ByVal lpsz As Long, ByRef pclsid As GUID) As Long

’ HKEY_CLASSES_ROOT/Interface/{7BF80980-BF32-101A-8BBB-00AA00300CAB} = IPicture
Private Const SIPICTURE As String = “{7BF80980-BF32-101A-8BBB-00AA00300CAB}”
Private Mstream As Object '二进制转换对象
Private Const adTypeBinary = 1 '二进制模式
Dim B() As Byte

Private Sub Form_Load()
Set Mstream = CreateObject(“ADODB.Stream”)
With Mstream
.Open '打开"ADODB.Stream"对象
.Type = adTypeBinary '二进制模式
.LoadFromFile App.Path & “\1.jpg” '图片路径
End With
B = Mstream.Read '将转好的二进制图片赋予BYTE值
Mstream.Close '关闭Mstream对象
End Sub

’ 将字节数组转换为IPicture
Public Function PictureFromRes(ByRef B() As Byte) As IPicture
On Error GoTo Errorhandler
Dim istrm As IUnknown
Dim tGUID As GUID
If Not CreateStreamOnHGlobal(B(LBound(B)), False, istrm) Then
CLSIDFromString StrPtr(SIPICTURE), tGUID
OleLoadPicture istrm, UBound(B) - LBound(B) + 1, False, tGUID, PictureFromRes
End If
Set istrm = Nothing
Exit Function
Errorhandler:
MsgBox “无法转换为IPicture!”
End Function

Private Sub Command1_Click()
Set Me.Picture = PictureFromRes(B)
End Sub

  • 4
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

键盘上的舞指

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值