有没有一种方法可以使图像分析更加动态,从而根据图片框的大小进行缩放?因此,我可以从网上添加任何想要的迷宫图像,并且可以立即使用。我尝试对某些变量使用ReDim:ReDim pixel(PictureBox1.Width,PictureBox1.Height)ReDim pixelData(PictureBox1.Width,PictureBox1.Height)并更改循环内的数值,但它似乎经常崩溃
我正在使用的图片:https://ibb.co/XVYBy1h
代码:
Dim FILE_NAME As String = "U:\Visual Studio 2015\Projects\Trace Test\Trace Test\bin\Debug\data.txt"
Dim objWriter As New System.IO.StreamWriter(FILE_NAME)
Do Until widthIMG = myBitmap.Width
lengthIMG += 1
pixels(widthIMG, lengthIMG) = myBitmap.GetPixel(widthIMG, lengthIMG)
Select Case pixels(widthIMG, lengthIMG).ToString
Case "Color [A=255, R=0, G=0, B=0]"
objWriter.Write(" Width: " & widthIMG.ToString & " Length: " & lengthIMG.ToString & " Color: " & "Black " & vbCrLf)
pixelsData(widthIMG, lengthIMG) = "Black"
Case "Color [A=255, R=255, G=255, B=255]"
objWriter.Write(" Width: " & widthIMG.ToString & " Length: " & lengthIMG.ToString & " Color: " & "White " & vbCrLf)
pixelsData(widthIMG, lengthIMG) = "White"
End Select
If lengthIMG = 342 Then
lengthIMG = 1
widthIMG += 1
End If
Continue Do
Loop
objWriter.Close()
答案 0 :(得分:0)
迭代图像像素的通常方法是使用两个循环,如下所示:
For y = 0 To myBitmap.Height - 1
For x = 0 To myBitmap.Width - 1
' do something with myBitmap.GetPixel(x, y)
Next
Next