Measurement Studio for VB6

cancel
Showing results for 
Search instead for 
Did you mean: 

The problem of IMAQ/Vision function?

I use ImageToArray function to extract a pixel array from an image. And I want to copy this array to the portion of the other image. I wrote a program as follow, but it dosen't work? Did anybody can help me.

Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (hpvDest As Any, hpvSource As Any, ByVal cbCopy As Long)

Private Sub Test_Click()
Dim pixelArray1 As Variant
Dim testarray() As Variant
Dim filename As String
Dim image1 As New CWIMAQImage
Dim h As Integer,w As Integer

ChDrive App.Path
ChDir App.Path
filename = CurDir & "\\test.png"
CWIMAQViewer1.Palette = cwimaqPaletteBinary
CWIMAQVision1.ReadImage image1, filename
ReDim testarray(5000, 5000)
h=
image1.Height
w=image1.Width
pixelArray1 = image1.ImageToArray
CopyMemory testarray(1000,1000),pixelArray1,h*w*16
End Sub
0 Kudos
Message 1 of 3
(3,309 Views)
Any time you use things like CopyMemory you need to be careful, and make sure you understand how things are really being stored in RAM. There are several things I would look at in your code.

First, the first argument of CopyMemory should be an address. It looks to me like you are giving the value stored in the 1000th row, and the 1000th column of testarray. If that element of the array actually contains an address then your in business, but more than likely it is undefined.

Second, arrays are stored in ram as one long continuous block of memory. The illusion of a 2D array is a higher level abstraction, done by the programming environment. The two arrays are stored as '1-D' continous blocks of memory. So, if your pixel array is 1000x1000, 5 rows of your so
urce will be stored in one row of your target. (5000/1000). The resulting image would definitely not be what you were expecting.
0 Kudos
Message 2 of 3
(3,309 Views)
If you are just wanting to copy one image onto another, you can use the ImagetoImage method.
0 Kudos
Message 3 of 3
(3,309 Views)