By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,289 Members | 1,260 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,289 IT Pros & Developers. It's quick & easy.

Converting an image for an RTF Document

P: n/a
Hello,

I am creating an RTF document server side for a report.

However I am having problems converting images into the required RTF
format.

I am converting the image into a string (binary) and including the
image syntax as per the RTF Specification, however the image is not
appearing when I view the document in Word or WordPad.

I would greatly appreciate any advice if anyone has done this before.

I have included some code:

Dim l_ConvertImage As New ImageConvert("images/decipher_logo.gif"))

l_RTFString.Append("{\sp{\sn fLayoutInCell}{\sv
1}}}\picscalex100\picscaley100\piccropl0\piccropr0 \piccropt0\piccropb0\picw"
& l_ConvertImage.l_ImageWidth & "\pich" & l_ConvertImage.l_ImageHeight
& " \picwgoal3615\pichgoal1200\jpegblip\bliptag-1988638119{\*\blipuid
8977ca59685e5fedce9ad02c42c5fff2\bin " & l_ConvertImage.l_ImageSize &
"}" & vbCrLf & vbCrLf)
l_RTFString.Append(l_ConvertImage.BinaryToString)
l_RTFString.Append("}}" & vbCrLf)

Private Class ImageConvert
Private l_ImageFile As System.Drawing.Bitmap
Private l_MemStream As MemoryStream
Public l_ImageWidth As Integer
Public l_ImageHeight As Integer
Public l_ImageSize As Integer

Public Sub New(ByVal v_ImageLocation As String)
l_ImageFile = New System.Drawing.Bitmap(v_ImageLocation)
l_ImageWidth = l_ImageFile.Width
l_ImageHeight = l_ImageFile.Height

l_MemStream = New MemoryStream()
l_ImageFile.Save(l_MemStream,
System.Drawing.Imaging.ImageFormat.Jpeg)
l_ImageSize = Convert.ToInt32(l_MemStream.Length)
End Sub

Public Function BinaryToString() As String
Dim l_ReturnString As New System.Text.StringBuilder()
Dim l_ImageBytes(l_ImageSize) As Byte

l_MemStream.Position = 0
l_MemStream.Read(l_ImageBytes, 0, l_ImageSize)
l_MemStream.Close()

Dim l_Enum As System.Collections.IEnumerator =
l_ImageBytes.GetEnumerator
While l_Enum.MoveNext
l_ReturnString.Append(l_Enum.Current)
End While

Return l_ReturnString.ToString
End Function
End Class

Thanks,
Mark
Nov 17 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.