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
Comments
0 comments
Please sign in to leave a comment.