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