Type tpMapFile
fhHeight as Long
fhWidth as Long
fhPixs() as Integer
End Type
初始化这个图象的过程就是:
Dim tPixs_Length as long
Dim tMap As tpMapFile
tPixs_Length=tMap.fhHeight*tMap.fhWidth - 1 '元素总数减去1(因为数组是从0开始的)
ReDim tMap.fhPixs(tPixs_Length)
假如我想在一个文件里保存多张图片,则修改成这样:
Type tpMapFile
fhHeight as Long
fhWidth as Long
fhPageCount as Long '页数
fhPixs() as Integer
End Type
初始化这个图象的过程就是:
Dim tPixs_Length as long
Dim tMap As tpMapFile
tPixs_Length=tMap.fhPageCount*tMap.fhHeight*tMap.fhWidth - 1
ReDim tMap.fhPixs(tPixs_Length)
Private Sub Command1_Click()
Dim tX As Long
Dim tY As Long
Dim tArray() As Long
Dim tArrayWidth As Long
Dim tArrayHeight As Long
tArrayWidth = 10
tArrayLine = 10
ArraySetBound tArray(), tArrayLine, tArrayWidth
For tX = 0 To 9
For tY = 0 To 9
ArrayPutValue tArray(), tY * 10 + tX, tX, tY, tArrayWidth
Next
Next
Text1.Text = ""
For tX = 0 To 9
For tY = 0 To 9
Text1.Text = Text1.Text & " " & ArrayGetValue(tArray(), tX, tY, tArrayWidth)
Next
Text1.Text = Text1.Text & vbCrLf
Next
End Sub
Public Function ArrayGetValue(ByRef pArray() As Long, ByVal pX As Long, ByVal pY As Long, ByVal pArrayWidth As Long) As Long
'返回数组pArray的pX,pY元素的值,数组pArray的宽度是pArrayWidth。
Dim tOutLong As Long
Dim tArray_Index As Long
tArray_Index = pY * pArrayWidth + pX
tOutLong = pArray(tArray_Index)
ArrayGetValue = tOutLong
End Function
Public Sub ArrayPutValue(ByRef pArray() As Long, ByVal pValue As Long, ByVal pX As Long, ByVal pY As Long, ByVal pArrayWidth As Long)
'将pValue写入数组pArray的pX,pY元素,数组pArray的宽度是pArrayWidth。
Dim tArray_Index As Long
tArray_Index = pY * pArrayWidth + pX
pArray(tArray_Index) = pValue
End Sub
Public Sub ArraySetBound(ByRef pArray() As Long, ByVal pX As Long, ByVal pY As Long)
'定义数组pArray的下界,使其容纳pX*pY个元素。
Dim tArray_Length As Long
tArray_Length = (pX * pY) - 1
ReDim pArray(tArray_Length)
End Sub