Main Menu

All times are in GMT -8 (DST) :: The time is now 5:10 am.

Login or Register
Create an account and register your LMI products to gain access to useful resources.

Register Account

Login

Sub Menu

Knowledge Base
Article Data
Article Ref
1438-ERXN-7227
Date Created
Wed, 25th Jul 2012
Date Modified
Mon, 6th Mar 2017

   How to create images in a HSDatabase without using the AcquisitionDevice in VB.NET, Part 2

Question 

How can I create images in a HSDatabase without using the AcquisitionDevice in VB.NET (Part 2)?

Answer 

This method is copying the pixels of a Bitmap, line by line, to set the HSImage pixels.

 


Public Function ImportImage(ByRef bmpImage As Bitmap) As Boolean
    ' copy image data from an in-memory Bitmap into a hexsight Color image


    Dim Results As Boolean

    Dim Himg As HSCLASSLIBRARYLib.HSImage

    Dim rect As Rectangle

    Dim BMPdata As Imaging.BitmapData

    Dim bytecount As Integer

    Himg = Me.mApplicationControl.Database.Image("Acquire", "Image")


    If (Himg Is Nothing) Then

        Me.mApplicationControl.Database.AddView("Acquire")
        Himg = Me.mApplicationControl.Database.AddImage("Acquire", "Image", HSCLASSLIBRARYLib.hsImageType.hsImage32bppRgb)

    End If

    Himg.Width = bmpImage.Width

    Himg.Height = bmpImage.Height

    bytecount = Himg.Width * Himg.Height * 4

    rect = New Rectangle(0, 0, bmpImage.Width, bmpImage.Height)

    BMPdata = bmpImage.LockBits(rect, Imaging.ImageLockMode.ReadOnly, Imaging.PixelFormat.Format32bppRgb)


    Try

        Dim i As Integer
        Dim bytes(bytecount) As Byte

        For i = 0 To BMPdata.Height - 1

            Marshal.Copy(BMPdata.Scan0.ToInt64() + BMPdata.Width * i * 4, bytes, BMPdata.Width * i * 4, BMPdata.Width * 4)
            Marshal.Copy(bytes, BMPdata.Width * i * 4, Himg.RawImagePointer + bytecount - BMPdata.Width * (i + 1) * 4, BMPdata.Width * 4)

        Next

        Results = True

    Catch ex As Exception

        Results = False

    End Try

    bmpImage.UnlockBits(BMPdata)

    Return Results

End Function