EXCEL的图像识别在链路预算中的应用




Sub Main()Const strBmpFile As String = 'C:\Mercator06.bmp'Dim arrByte() As ByteDim PixelCol As Long, PixelRow As LongDim CellCol As Long, CellRow As LongDim i As Long, j As LongDim lngPos As Long, Zeroize As Long Open strBmpFile For Binary As #1ReDim arrByte(LOF(1) - 1)Get #1, , arrByteClose #1 For i = 0 To 3PixelCol = PixelCol + arrByte(i + 18) * 256 ^ iNextFor i = 0 To 3PixelRow = PixelRow + arrByte(i + 22) * 256 ^ iNext If PixelCol Mod 4 <> 0 Then Zeroize = PixelCol Mod 4 Cells.ClearFor i = PixelRow To 1 Step -1CellRow = CellRow + 1CellCol = 0For j = 1 To PixelCol * 3 Step 3CellCol = CellCol + 1lngPos = 53 + j + (i - 1) * (PixelCol * 3 + Zeroize)Cells(CellRow, CellCol).Interior.Color = RGB(arrByte(lngPos + 2), arrByte(lngPos + 1), arrByte(lngPos))NextNextEnd Sub
Sub tst()Application.ScreenUpdating = FalseDim i, j, kWith Sheets('雨区颜色-1')For i = 1 To 3142For j = 1 To 3142k = .Cells(j, i).Interior.ColorIf k = 16777215 Then .Cells(j, i) = 'A' ElseIf k = 65280 Then .Cells(j, i) = 'B' ElseIf k = 16764160 Then .Cells(j, i) = 'C' ElseIf k = 15066597 Then .Cells(j, i) = 'D' ElseIf k = 13369343 Then .Cells(j, i) = 'E' ElseIf k = 52735 Then .Cells(j, i) = 'F' ElseIf k = 26367 Then .Cells(j, i) = 'G' ElseIf k = 16738047 Then .Cells(j, i) = 'H' ElseIf k = 10014157 Then .Cells(j, i) = 'J' ElseIf k = 9764788 Then .Cells(j, i) = 'K' ElseIf k = 39645 Then .Cells(j, i) = 'L' ElseIf k = 65535 Then .Cells(j, i) = 'M' ElseIf k = 16764415 Then .Cells(j, i) = 'N' ElseIf k = 16777140 Then .Cells(j, i) = 'P'Else .Cells(j, i) = 'Q' End IfNext jNext iEnd WithApplication.ScreenUpdating = TrueEnd Sub



赞 (0)
