| 000000 |
06-30-2012 02:45 AM |
JPG Image to Hex Triplet?
I have created a program in Visual Basic that can display any file into its hex equivalent. I am wondering how I could potentially show hex triplets (i.e HTML code colors) instead of groups of two. Any ideas?
Source code:
Code:
Imports System.Text
Imports System.IO
Public Class frmMain
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LoadFile.Click
Dim ArrayHold() As Byte
Dim Index As Integer = 0
Dim Str As New StringBuilder
Dim tStr As String = ""
Dim tempStr As String = ""
Dim IndexEnd As Integer = 0
Dim InputString As String = ""
OpenDia.Filter = "All Files|*.*"
If OpenDia.ShowDialog = Windows.Forms.DialogResult.OK Then
' ArrayHold = My.Computer.FileSystem.ReadAllBytes(OpenDia.FileName)
'==============================================================
Dim myStreamReader As StreamReader = Nothing
' Ensure that the creation of the new StreamReader is wrapped in a
' Try-Catch block, since an invalid filename could have been used.
' Create a StreamReader using a Shared (static) File class.
myStreamReader = File.OpenText(OpenDia.FileName)
' Read the entire file in one pass, and add the contents to
' txtFileText text box.
InputString = myStreamReader.ReadToEnd()
'Convert string to byte and copy to byte array
ArrayHold = Encoding.Default.GetBytes(InputString)
'=================================================================
'ArrayHold = FileSystem.ReadAllBytes(OpenDia.FileName)
Do
IndexEnd = Index + 9
For x As Integer = Index To IndexEnd
If x > UBound(ArrayHold) Then
Str.Append(" ")
tempStr = tempStr & " "
Else
tStr = UCase(Convert.ToString(ArrayHold(x), 16))
If tStr.Length < 2 Then tStr = "0" & tStr
Str.Append(tStr & " ")
If ArrayHold(x) < 32 Then
tempStr = tempStr & ". "
Else
tempStr = tempStr & Chr(ArrayHold(x)) & " "
End If
End If
Next
Str.Append(" | " & tempStr & vbCrLf)
tempStr = ""
Index = Index + 10
Loop While IndexEnd < UBound(ArrayHold)
DispalyHex.Text = Str.ToString
End If
End Sub
Private Sub DispalyHex_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DispalyHex.TextChanged
End Sub
End Class
|