PC Review


Reply
Thread Tools Rate Thread

Convert jpeg's to HEX

 
 
=?Utf-8?B?ZG9udEdldFN0dWNrTGlrZU1l?=
Guest
Posts: n/a
 
      6th Aug 2005
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.
 
Reply With Quote
 
 
 
 
David Browne
Guest
Posts: n/a
 
      6th Aug 2005

"dontGetStuckLikeMe" <(E-Mail Removed)> wrote in
message news:43F163F2-F6DF-4FD3-A309-(E-Mail Removed)...
>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.


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


 
Reply With Quote
 
Morten Wennevik
Guest
Posts: n/a
 
      6th Aug 2005
Hi,

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

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

--
Happy coding!
Morten Wennevik [C# MVP]
 
Reply With Quote
 
=?Utf-8?B?ZG9udEdldFN0dWNrTGlrZU1l?=
Guest
Posts: n/a
 
      7th Aug 2005
Thank's, now it's all working!!!
 
Reply With Quote
 
 
 
Reply

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
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
convert jpeg file to jpeg image =?Utf-8?B?U291bHJoeWRlcg==?= Windows XP Photos 0 3rd Mar 2007 06:50 PM
convert pdf to jpeg perky Windows XP General 3 28th Oct 2006 03:18 AM
convert pdf to jpeg perky Windows XP Photos 4 27th Oct 2006 08:25 PM
Convert EPS to JPEG Klaus Jensen Microsoft Dot NET Framework 0 6th Jan 2006 10:28 AM
convert ppm to jpeg Kim Schulz Microsoft C# .NET 3 18th Aug 2004 04:14 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:44 PM.