1
花了一個小時試圖解決這個問題,我決定作爲一個問題。VB返回小數字溢出
我在圖像相關的項目中使用VB.Net 2010。在這一步中,我必須比較兩幅圖像像素的顏色,以確定它們的相似程度。要做到這一點,我設計了下面的代碼:
''get both images as bitmaps
Dim act As New Bitmap("cam.bmp")
Dim map As New Bitmap(bmap)
''declare the variable that counts the different pixels
Dim count As Integer = 0
''declare the variables that represent the colors
Dim val As Long = 0
Dim valr As Long = 0
Dim valg As Long = 0
Dim valb As Long = 0
''analize both images pixel by pixel
For x = 1 To act.Width - 1 Step 1
For y = 1 To act.Height - 1 Step 1
valr = 0
valg = 0
valb = 0
''determine how different the pixels are
valr = Math.Abs(act.GetPixel(x, y).R - map.GetPixel(x, y).R)
valg = Math.Abs(act.GetPixel(x, y).G - map.GetPixel(x, y).G)
valb = Math.Abs(act.GetPixel(x, y).B - map.GetPixel(x, y).B)
val = Long.Parse(Int((valr + valg + valb)/3).ToString)
''if enough different, add 1 to count
If val > 50 Then
count += 1
End If
Next
Next
''show how many pixels are different in proportion
MsgBox((count/(act.Width * act.Height)).ToString)
運行此代碼時,溢出的部分valr = Math.Abs(act.GetPixel(x, y).R - map.GetPixel(x, y).R)
發生。沒有其他問題發生。
謝謝!它解決了我的問題。 – Elemermelada