Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / August 2005

Tip: Looking for answers? Try searching our database.

Convert jpeg's to HEX

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
dontGetStuckLikeMe - 06 Aug 2005 02:30 GMT
I want to convert jpeg's to Hex but I don't really seem to get it right.
The code I use is the following:

Private Function tmpGetByteFileFromDisk(ByVal FilePath As String) As Byte()
       Try
           Dim fs As FileStream = New FileStream(FilePath, FileMode.Open,
FileAccess.Read)
           Dim br As BinaryReader = New BinaryReader(fs)
           Dim i As Integer
           Dim photo As String
           br.Read()
           Dim p As String
           For i = 0 To 40697
               p = Hex(br.ReadByte)
               If Len(p) = 1 Then
                   photo = photo & "0" & p
               Else
                   photo = photo & p
               End If
           Next
           TextBox1.Text = photo
           br.Close()
           fs.Close()

I want this done to insert the image into a rtf-document using the
streamwriter object, this way I can generate rtf-documents without all the
overhead of starting the word.application.

Suggestions greatly appreciated.
David Browne - 06 Aug 2005 19:03 GMT
>I want to convert jpeg's to Hex but I don't really seem to get it right.
> The code I use is the following:
[quoted text clipped - 26 lines]
>
> Suggestions greatly appreciated.

Here's a suggestion:

   Private Function FileToHex(ByVal FilePath As String) As String

       Dim fs As FileStream = New FileStream(FilePath, _
                                            FileMode.Open, _
                                            FileAccess.Read)
       Dim buf(CInt(fs.Length)) As Byte
       fs.Read(buf, 0, buf.Length)
       fs.Close()
       Static hexChars() As Char = {"0"c, "1"c, "2"c, "3"c, "4"c, "5"c,
"6"c, _
                               "7"c, "8"c, "9"c, "A"c, "B"c, "C"c, "D"c,
"E"c, "F"c}

       Dim sb As New Text.StringBuilder(buf.Length * 2)
       For Each b As Byte In buf
           Dim n1 As Integer = b >> 4
           Dim n2 As Integer = b And 15
           sb.Append(hexChars(n1))
           sb.Append(hexChars(n2))
       Next
       Return sb.ToString

   End Function

David
dontGetStuckLikeMe - 07 Aug 2005 17:46 GMT
Thank's, now it's all working!!!
Morten Wennevik - 06 Aug 2005 19:26 GMT
Hi,

I'm not familiar with images in rtf but this page may be of interest:

http://dotnet.org.za/pieter/archive/2005/03/29/15961.aspx

Signature

Happy coding!
Morten Wennevik [C# MVP]


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.