Go Back   CodingForums.com > :: Computing & Sciences > Computer Programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 06-30-2012, 02:45 AM   PM User | #1
000000
New to the CF scene

 
Join Date: Jun 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
000000 is an unknown quantity at this point
Exclamation 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
000000 is offline   Reply With Quote
Reply

Bookmarks

Tags
convert, hex triplet, image, jpg

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:08 AM.


Advertisement
Log in to turn off these ads.