Imports System
Imports System.IO
Public Class readerImagePGM
Public Shared Sub Main()
Console.WriteLine("Enter name of file PGM")
Dim name As String = Console.ReadLine()
Dim filePGM As FileStream = File.OpenRead(name)
Dim data As Byte() = New Byte(filePGM.Length - 1) {}
filePGM.Read(data, 0, filePGM.Length)
filePGM.Close()
Dim mesures As String = ""
Dim i As Integer = 3
Do
mesures += Convert.ToChar(data(i))
i += 1
Loop While data(i) <> 10
i += 1
Dim size As String()
Dim width, height As Integer
size = mesures.Split(" "c)
width = Convert.ToInt32(size(0))
height = Convert.ToInt32(size(1))
Dim colorTone As String = ""
Do
colorTone += Convert.ToChar(data(i))
i += 1
Loop While data(i) <> 10
i += 1
Dim amount As Integer = 0
For j As Integer = i To filePGM.Length - 1
If data(j) >= 200 Then
Console.Write(" ")
ElseIf data(j) >= 150 OrElse data(j) <= 199 Then
Console.Write(".")
ElseIf data(j) >= 100 OrElse data(j) <= 149 Then
Console.Write("-")
ElseIf data(j) >= 50 OrElse data(j) <= 99 Then
Console.Write("=")
ElseIf data(j) >= 0 OrElse data(j) <= 49 Then
Console.Write("#")
End If
amount += 1
If amount Mod width = 0 Then Console.WriteLine()
Next
End Sub
End Class