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 6758287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:45:57+00:00 2026-05-26T13:45:57+00:00

I am attempting to insert an image into a rich text file. I have

  • 0

I am attempting to insert an image into a rich text file. I have read some of the answers already, but I’m not getting it quite right. The code I am using is as follows:

            string[] imgfiles = Directory.GetFiles(dirin, "*.png");
            foreach (string imageFileName in imgfiles)
            {
                var someImage = Image.FromFile(imageFileName);
                MemoryStream memStream = new MemoryStream();
                someImage.Save(memStream, ImageFormat.Png);
                byte[] imgbytedata = memStream.ToArray();
                memStream.Close();
                memStream.Dispose();
                StringBuilder sb = new StringBuilder();
                for(int i = 0; i < imgbytedata.Length; i++)
                {
                    sb.Append(imgbytedata[i]);
                }
                var imgstr = "{" + string.Format("\\pict\\pngblip\\picw{0}\\pich{1}\\picwgoal{0}\\pichgoal{1}\\bin binary {2}", someImage.Width, someImage.Height, sb.ToString()) + "}";
                sb = null;

                rtb.AppendText(imgstr);
            }
  • 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-05-26T13:45:58+00:00Added an answer on May 26, 2026 at 1:45 pm

    When you are building your string from the byte array, you are appending the string version of your byte data, i.e. “76”,”127″,”90″, etc.

    One major problem (I don’t know if this is your actual problem) is that when you attempt to read it, the reader has no idea how to extract bytes from it. Take this example…

    var c = new StringBuilder();
    c.Append(6);
    c.Append(64);
    Console.WriteLine(c.ToString());
    

    OUTPUT:

    "664"
    

    Solution: Convert your byte array into a base64String with Convert.ToBase64String and store that in the file.

    Like so….

    var c = Convert.ToBase64String(new byte[] {6, 64});
    Console.WriteLine(c);
    Console.WriteLine();
    foreach (var entry in Convert.FromBase64String(c))
        Console.WriteLine(entry);
    

    OUTPUT

    "BkA="
    
    6
    64
    

    Another potential problem: I’ve heard tell that using string.Format with exceptionally large strings can cause problems. I can fathom a case in which you generate memory exceptions with large image files.

    Solution: Don’t use string.Format. Either append your headers to the StringBuilder first OR write the header and image data in two separate actions.

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

Sidebar

Related Questions

I am attempting to insert data into a local SQLITE database file from a
I'm attempting to insert some integers into a Postgres table with the following somewhat
I am attempting to insert text from a database into a custom TextArea component,
Attempting to insert an escape character into a table results in a warning. For
I am attempting to insert a Canvas3D object inside a Swing JPanel, but the
I am attempting to insert a copy of a row from one table into
I am attempting to insert a mass of records into SQL Server 2005 from
I am attempting to insert a custom behavior into my service client, following the
I have not done much database programming at all. I am working from some
I'm attempting to insert an array into a SQL Server database. 1/4 is copied

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.