Main Menu

All times are in GMT -8 (DST) :: The time is now 5:12 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
4782-TPAH-6906
Date Created
Mon, 11th May 2015
Date Modified
Mon, 6th Mar 2017

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

Question 

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

Answer 

 This method is using the AttachImagePointer() function to set the HSImage pixels from a pre-filled buffer.

 


Dim lBytePointer As IntPtr

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    Dim lBitmap As New System.Drawing.Bitmap("C:/image.jpg")
    FillBuffer(lBitmap, lBytePointer)

    AttachImageBuffer(lBytePointer, lBitmap.Width, lBitmap.Height)

End Sub

Public Function FillBuffer(ByRef bmpImage As Bitmap, ByRef bytePointer As IntPtr) As Boolean

    ' Copy image data from an in memory Bitmap into a byte pointer array.
    ' This buffer can be filled from another process.

    Dim Results As Boolean
    Dim rect As Rectangle
    Dim BMPdata As Imaging.BitmapData
    Dim bytecount As Integer

    rect = New Rectangle(0, 0, bmpImage.Width, bmpImage.Height)
    BMPdata = bmpImage.LockBits(rect, Imaging.ImageLockMode.ReadOnly, Imaging.PixelFormat.Format32bppRgb)

    bytecount = bmpImage.Width * bmpImage.Height * 4
    Results = True

    Try

        Dim i As Integer
        Dim bytes(bytecount) As Byte

        Marshal.FreeHGlobal(bytePointer)
        bytePointer = Marshal.AllocHGlobal(bytecount)

        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, bytePointer.ToInt64() + bytecount - BMPdata.Width * (i + 1) * 4, BMPdata.Width * 4)

        Next

    Catch ex As Exception

        Results = False

    End Try

    bmpImage.UnlockBits(BMPdata)

    Return Results

End Function

Public Function AttachImageBuffer(ByVal bytePointer As IntPtr, ByVal width As Integer, ByVal height As Integer) As Boolean

    ' Attach a byte pointer array to a hexsight Color image

    Dim Results As Boolean
    Dim Himg As HSCLASSLIBRARYLib.HSImage

    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 = width
    Himg.Height = height
    Results = True

    Try

        Himg.AttachImagePointer(bytePointer, width, height)

    Catch ex As Exception

        Results = False

    End Try

    Return Results

End Function 

Article Comments 

Comment posted
You......can.find.the.exact.answer.or.file.you.need.just.by.choosing.and.clicking.on.the......newly.designed.categories,.starting.from.top.to.bottom..Also,.you.can.enter.a.general......search.of.any.level.category,.and.then.continue.to.enter.search.keywords.to.drill......down.to.find.your.answer..When.you.access.the.new.Knowledge.Base,.you.will.discover.a.more.comprehensive.and.easier.to.use.search.engine.for.Icom-related.information..Icom.s.Knowledge.Base.is.organized.to.help.you.find.solutions.faster!.Optionally.override.the.settings.defined.at.the.top.of.the.highslide..SlideDeck.PRO.in.the.same.\nfolder.as.this.file.to.view.the.demo..To.use.this.code.example,.you.MUST.own.a.copy.of.\nSlideDeck.PRO..In.January.you.can.expect.a.new.look.to.our.knowledge.base......For.example,.if.you.enter.the.search.term.'activate',.the.Knowledgebase.searches.for.'activation',.'activations',.'activated'.and.'activates'.in.addition.to.'activate..Remember.that.the.Knowledgebase.searches.for.all.forms.of.your.search.terms,.including.singular,.plural.and.all.verb.tenses......That..makes.it.easier.for.you.to.get.technical.support.at.times.when..our.support.staff.is.unavailable..You.may.use.the.knowledgebase.to.get.technical.support.at.times.when.our.support.staff.is.unavailable..When.a.new.question.arises,.it.is.added..to.the.database.and.is.published.to.the.world-wide.web..The.Keil.Support.Knowledgebase.is.a.database.of.technical.support..questions.and.answers..Many.of.the.features.of.our.database.are.the.result.of.your..suggestions..By.continuing.to.use.our.site,.you.consent.to.ARM’s.Privacy.Policy..This.site.uses.cookies.to.store.information.on.your.computer..You.can.search.manuals,.appnotes,.and.other.resources,.too!.ARM’s.Privacy.Policy.has.been.updated......