老師給的,也沒整明白啥意思,除錯時老是提示下標越界,求指點。

'頭檔案
private type bitmapfileheader
bftype As Integer
bfsize As Long
bfreserved1 As Integer
bfreserved2 As Integer
bfoffbits As Long
End Type
'頭資訊
private type bitmapinfoheader
bisize As Long
biwidth As Long
biheight As Long
biplanes As Integer
bibitcount As Integer
bicompression As Long
bisizeimage As Long
bixpelspermeter As Long
biypelspermeter As Long
biclrused As Long
biclrimportant As Long
End Type
'調色板
privatae type rgbquad
rgbblue As Byte
rgbgreen As Byte
rgbred As Byte
rgbreserved As Byte
End Type
Dim bf As bitmapfileheader
Dim bl As bitmapinfoheader
Dim piccol(1024, 1024, 2) As Byte
Dim xpos As Integer
Dim ypos As Integer
Dim picturename As String
CommonDialog1.DialogTitle = "打開影像檔案"
CommonDialog1.FileName = ""
CommonDialog1.Filter = "影像檔案(*.bmp)|*.bmp"
CommonDialog1.ShowOpen
picturename = CommonDialog1.FileName
If picturename = "" Then
MsgBox "請先打開影像檔案,再讀資料!", vbCritical, "錯誤"
Exit Sub
End If
Picture1.Picture = LoadPicture(CommonDialog1.FileName)
Dim colornum, i, j, kk, l As Integer
Dim pix As Byte
Dim col As Byte
Open picturename For Binary As #1
Get #1, , bf
Get #1, , bl
xpos = bl.biwidth
ypos = bl.biheight
colornum = bl.bibitcount
Screen.MousePointer = 12
Select Case colornum
Case 24
For i = 0 To ypos - 1
For j = 0 To xpos - 1
For l = 0 To 2
Get #1, , col
piccol(j, i, l) = col
Next
Next
If Int((xpos * 3) / 4) <> (xpos * 3) / 4 Then
For kk = 1 To 4 - ((xpos * 3) Mod 4)
Get #1, , pix
Next
End If
Next
Case 8
Dim Index As Byte
Dim palentry As Byte
Dim unused As Integer
Dim rgbpalette(255, 2) As Byte
Dim palettesize As Integer
palettesize = 2 ^ colornum
For i = 0 To palettesize - 1
For j = 0 To 2
Get #1, , palentry
rgbpalette(i, j) = palentry
Next
Get #1, , palentry
unused = palentry
If unused <> 0 Then
GoTo readend
End If
Next
readend: For i = 0 To ypos - 1
For j = 0 To xpos - 1
Get #1, , Index
piccol(j, i, 0) = rgbpalette(Index, 0)
piccol(j, i, 1) = rgbpalette(Index, 1)
piccol(j, i, 2) = rgbpalette(Index, 2)
Next
If Int(xpos / 4) <> xpos / 4 Then
For kk = 1 To 4 - xpos Mod 4
Get #1, , pix
Next
End If
Next
End Select
Close #1
Screen.MousePointer = 0
Print "bftype="; bf.bftype
Print "bfSize="; bf.bfsize
Print "bisize="; bl.bisize
Print "biwidth="; bl.biwidth
Print "biheight="; bl.biheight
Print "bibitcount="; bl.bibitcount
Print "bicompression="; bl.bicompression
Print "bisizeimage="; bl.bisizeimage
Print "bixpelspermeter="; bl.bixpelspermeter
Print "biypelspermeter="; bl.biypelspermeter
Print "biclrimportant="; bl.biclrimportant
uj5u.com熱心網友回復:
哪一句提示下標越界?uj5u.com熱心網友回復:
找個課外老師唄。
piccol(j, i, 0) = rgbpalette(Index, 0)
piccol(j, i, 1) = rgbpalette(Index, 1)
piccol(j, i, 2) = rgbpalette(Index, 2)
陣列問題,判斷一下陣列維數唄。
uj5u.com熱心網友回復:
piccol(j, i, l) = col就這一句,不過我換個圖片,又沒錯誤了,不懂
uj5u.com熱心網友回復:
看這個陣列好像是1024*1024像素的,圖片大小超過了報越界很正常;轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/13516.html
標籤:VB基礎類
上一篇:求大佬幫助看下這個vba邏輯
下一篇:VB學習版2010
