ICImagingControl.MemoryGetImageData Method

Provides direct access to the image data of Imaging Control.
Syntax:
Public Function MemoryGetImageData() As Variant
Return Value:

The MemoryGetImageData method returns a SAFEARRAY of Byte in a Variant that provides direct access to the internal image data. Calling this method does not copy the image data. This SAFEARRAY has the dimensions Width = (0 To ( ICImagingControl.ImageWidth * ( ICImagingControl.ImageBitsPerPixel / 8)) - 1) Height = (0 To ICImagingControl.ImageHeight - 1)

Remarks:

The Variant must be released by a call to ICImagingControl.MemoryReleaseImageData. Not releasing it may lead to a black buffer or even worse side effects. This is, because MemoryGetImageData locks the image buffer to prevent it from being overwritten.

The data is arranged bottom up because the buffer has similar properties to a DIB. So the first row of the image is the last row in the image buffer.

The pixel format in the buffer is equal to the ICImagingControl.MemoryCurrentGrabberColorformat.

Sample:

This example snaps an image and inverts it. This sample requires the VideoFormat and MemoryCurrentGrabberColorformat to be set to 8 bit format:

Private Sub cmdStart_Click()
    Dim ImageData As Variant
    Dim x As Integer, y As Integer

    ICImagingControl1.MemorySnapImage
    ImageData = ICImagingControl1.MemoryGetImageData

    For y = 0 To ICImagingControl1.ImageHeight - 1
        For x = 0 To ICImagingControl1.ImageWidth - 1
            ImageData(x, y) = 255 - ImageData(x, y)
        Next x
    Next y

    ICImagingControl1.MemoryReleaseImageData ImageData
    ICImagingControl1.Display
End Sub
See also: ICImagingControl, ICImagingControl.MemoryReleaseImageData, ICImagingControl.ImageWidth, ICImagingControl.ImageHeight, ICImagingControl.ImageBitsPerPixel, ICImagingControl.MemoryGetDib

<< ICImagingControl