如何带“System.Drawing.Image"到 DIB [英] How to bring "System.Drawing.Image" to DIB
问题描述
我创建了一个可使用的 COM 类库.
I have created a consumable COM Class Library.
类库获取相机的图像.它是图像/位图类型.
The class library gets the image of a camera. It's of type Image / Bitmap.
我在 VB6 中使用类库,我需要在 VB6 中显示此图像.
I consume the class library in VB6, and I need to show this image in VB6.
如何将此 System.Drawing.Image 转换为 VB6 可以显示的内容?
How could I convert this System.Drawing.Image to something that VB6 can display?
我可以使用 DIB(使用 CreateDIBSection 等)吗?
Can I use a DIB (using CreateDIBSection, etc.)?
如果是,System.Drawing.Image 究竟如何转换为 DIB?
If yes, how exactely can a System.Drawing.Image be converted to a DIB?
谢谢!
推荐答案
这是我过去所做的.首先,有几个先决条件:
Here's what I've done in the past. First, a couple prerequisites:
- 您从 COM 类库中获得了一个 Byte()
- 您设置了对 Microsoft Windows 图像采集库的引用
有了这些,代码就很简单了.Camera
是一个 COM 类库,其中 Retrieve
方法返回一个被加载到 Image 控件中的 Byte():
With these in place, the code is pretty simple. Camera
is a COM Class Library where the Retrieve
method returns a Byte() that gets loaded into an Image control:
Option Explicit
Private Sub cmdLoad_Click()
Dim cam As Camera.Image
Set cam = New Camera.Image
Image1.Picture = LoadPictureFromByteArray(cam.Retrieve())
End Sub
Private Function LoadPictureFromByteArray(Image() As Byte) As StdPicture
Dim vec As WIA.Vector
Set vec = New WIA.Vector
vec.BinaryData = Image
Set LoadPictureFromByteArray = vec.ImageFile.FileData.Picture
End Function
这篇关于如何带“System.Drawing.Image"到 DIB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!