Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7914149
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T14:01:00+00:00 2026-06-03T14:01:00+00:00

I Started with this C# Question I’m trying to Display a bmp image inside

  • 0

I Started with this C# Question

I’m trying to Display a bmp image inside a rtf Box for a Bot program I’m making.
This function is supposed to convert a bitmap to rtf code whis is inserted to another rtf formatter srtring with additional text. Kind of like Smilies being used in a chat program.

For some reason the output of this function gets rejected by the RTF Box and Vanishes completly. I’m not sure if it the way I’m converting the bmp to a Binary string or if its tied in with the header tags

lb.SelectedRtf = FormatText(build.ToString, newColor)

 'returns the RTF string representation of our picture
    Public Shared Function PictureToRTF(ByVal Bmp As Bitmap) As String

    'Create a new bitmap
    Dim BmpNew As New Bitmap(Bmp.Width, Bmp.Height, Imaging.PixelFormat.Format24bppRgb)
    Dim gr = Graphics.FromImage(BmpNew)
    gr.DrawimageUnscaled(Bmp, 0, 0)
    gr.dispose()

    Dim stream As New MemoryStream()
    BmpNew.Save(stream, System.Drawing.Imaging.ImageFormat.Bmp)

        Dim bytes As Byte() = stream.ToArray()

        Dim str As String = BitConverter.ToString(bytes, 0).Replace("-", String.Empty)

        'header to string we want to insert
        Using g As Graphics = Main.CreateGraphics()
            xDpi = g.DpiX
            yDpi = g.DpiY
        End Using

        Dim _rtf As New StringBuilder()

        ' Calculate the current width of the image in (0.01)mm
        Dim picw As Integer = CInt(Math.Round((Bmp.Width / xDpi) * HMM_PER_INCH))

        ' Calculate the current height of the image in (0.01)mm
        Dim pich As Integer = CInt(Math.Round((Bmp.Height / yDpi) * HMM_PER_INCH))

        ' Calculate the target width of the image in twips
        Dim picwgoal As Integer = CInt(Math.Round((Bmp.Width / xDpi) * TWIPS_PER_INCH))

        ' Calculate the target height of the image in twips
        Dim pichgoal As Integer = CInt(Math.Round((Bmp.Height / yDpi) * TWIPS_PER_INCH))

        ' Append values to RTF string
        _rtf.Append("{\pict\wbitmap0")
        _rtf.Append("\picw")
        _rtf.Append(Bmp.Width.ToString)
        '  _rtf.Append(picw.ToString)
        _rtf.Append("\pich")
        _rtf.Append(Bmp.Height.ToString)
        ' _rtf.Append(pich.ToString)
        _rtf.Append("\wbmbitspixel24\wbmplanes1")
        _rtf.Append("\wbmwidthbytes40")
        _rtf.Append("\picwgoal")
        _rtf.Append(picwgoal.ToString)
        _rtf.Append("\pichgoal")
        _rtf.Append(pichgoal.ToString)
        _rtf.Append("\bin ")

        _rtf.Append(str.ToLower & "}")
        Return _rtf.ToString
    End Function

Public Function FormatText(ByVal data As String, ByVal newColor As fColorEnum) As String
    data = System.Net.WebUtility.HtmlDecode(data)
    data = data.Replace("|", " ")
    Dim reg As New Regex("\$(.[0-9]+)\$")
    If reg.IsMatch(data) Then
        Dim meep As String = Regex.Match(data, "\$(.[0-9]+)\$").Groups(1).ToString
        Dim idx As Integer = Convert.ToInt32(meep)
        Dim img As String = Fox2RTF(idx)

        If img IsNot Nothing Then data = Regex.Replace(data, "\$(.[0-9]+)\$", img)
    End If
    Dim myColor As System.Drawing.Color = fColor(newColor)
    Dim ColorString = "{\colortbl ;"
    ColorString += "\red" & myColor.R & "\green" & myColor.G & "\blue" & myColor.B & ";}"
    Dim FontSize As Integer = cMain.ApFont.Size
    Dim FontFace As String = cMain.ApFont.Name
    FontSize *= 2
    Dim test As String = "{\rtf1\ansi\ansicpg1252\deff0\deflang1033" & ColorString & "{\fonttbl{\f0\fcharset0 " & FontFace & ";}}\viewkind4\uc1\fs" & FontSize.ToString & data & "\par}"
    Return "{\rtf1\ansi\ansicpg1252\deff0\deflang1033" & ColorString & "{\fonttbl{\f0\fcharset0 " & FontFace & ";}}\viewkind4\uc1\fs" & FontSize.ToString & data & "\cf0 \par}"
End Function
Private Function Fox2RTF(ByRef Img As Integer) As String
    Dim shape As New FurcadiaShapes(Paths.GetDefaultPatchPath() & "system.fsh")
    Dim anims As Bitmap() = Helper.ToBitmapArray(shape)
    ' pic.Image = anims(Img)

    Return PictureToRTF.PictureToRTF(anims(Img))

End Function
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T14:01:01+00:00Added an answer on June 3, 2026 at 2:01 pm

    Never found the Soultion I was hoping for with this.. But I did find a work around http://www.codeproject.com/Articles/30902/RichText-Builder-StringBuilder-for-RTF

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I had previously asked this question, trying to get started with this code: The
I first referenced this question to get started, but reached a roadblock when trying
I originally started this question in another thread, but that thread was sorta, kinda
I've started this question Named route with nested resources , and it lead me
Started with this question: OpenID. How do you logout OK. So OpenID does not
I know this question has kind-a started religious wars in past and there might
Forgive if this question is silly. I just started reading the SugarCRM developer documentation
Let me preface this question. I have just started using jquery, so please be
I've started to become a Good Citizen, as per this question here: Domain compatibility:
This started as a question, but turned into a solution as I did some

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.