How to bring “System.Drawing.Image” to DIB

狂风中的少年 提交于 2021-01-27 07:23:39

问题


I have created a consumable COM Class Library.

The class library gets the image of a camera. It's of type Image / Bitmap.

I consume the class library in VB6, and I need to show this image in VB6.

How could I convert this System.Drawing.Image to something that VB6 can display?

Can I use a DIB (using CreateDIBSection, etc.)?

If yes, how exactely can a System.Drawing.Image be converted to a DIB?

Thank you!


回答1:


Here's what I've done in the past. First, a couple prerequisites:

  • you get a Byte() from the COM Class Library
  • you set a reference to Microsoft Windows Image Aquisition Library

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


来源:https://stackoverflow.com/questions/61370388/how-to-bring-system-drawing-image-to-dib

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!