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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T07:59:38+00:00 2026-05-15T07:59:38+00:00

I am converting images to byte array and storing in a text file using

  • 0

I am converting images to byte array and storing in a text file using the following code. I am retrieving them successfully as well.

My concern is that the quality of the retrieved image is not up to the expectation. Is there a way to have better conversion to byte array and retrieving? I am not worried about the space conception.

Please share your thoughts.

    string plaintextStoringLocation = @"D:\ImageSource\Cha5.txt";
    string bmpSourceLocation = @"D:\ImageSource\Cha50.bmp";

    ////Read image
    Image sourceImg = Image.FromFile(bmpSourceLocation);

    ////Convert to Byte[]
    byte[] clearByteArray = ImageToByteArray(sourceImg);


    ////Store it for future use (in plain text form)
    StoreToLocation(clearByteArray, plaintextStoringLocation);

    //Read from binary
    byte[] retirevedImageBytes = ReadByteArrayFromFile(plaintextStoringLocation);

    //Retrieve from Byte[]
    Image destinationImg = ByteArrayToImage(retirevedImageBytes);

    //Display Image
    pictureBox1.Image = destinationImg;

EDIT: And the solution is – use Base64

            //Plain Text Storing Location
            string plaintextStoringLocation = @"D:\ImageSource\GirlInflower23.txt";
            string bmpSourceLocation = @"D:\ImageSource\GirlInflower1.bmp";

            ////Read image
            Image sourceImg = Image.FromFile(bmpSourceLocation);


            string base64StringOfIMage = ImageToBase64(sourceImg, ImageFormat.Bmp);

            byte[] byteOfString = Convert.FromBase64String(base64StringOfIMage);


            StoreToLocation(byteOfString, plaintextStoringLocation);

            byte[] retrievedBytesForStrimngForImage = ReadByteArrayFromFile(plaintextStoringLocation);


            MemoryStream memStream = new MemoryStream(retrievedBytesForStrimngForImage);
            //memStream.Read();

            Image retrievedImg = Image.FromStream(memStream);
            pictureBox1.Image = retrievedImg;
  • 1 1 Answer
  • 2 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-15T07:59:38+00:00Added an answer on May 15, 2026 at 7:59 am

    Yes, it is possible to get completely lossless storage. If you just store it in its original BMP format there will be no problem. I assume you are converting it to text because you want to send it via some protocol where binary characters will be corrupted.

    Instead of whatever you are doing, you could consider using Convert.ToBase64String.

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

Sidebar

Related Questions

Is converting a file to a byte array the best way to save ANY
I am converting Base64 code to image and I am using following way to
I am struggling converting image to byte array using client side script. I have
I am using the following c# code to convert an image file to a
I am using following code in WPF to display image in webcam usingEmguCv library
I need a code snippt for converting DataHandler to byte[] . This data handler
I have a function which extracts a file into a byte array (data). int
I'm converting a image to gray scale in Java with the following code: BufferedImage
I need help in converting a file received from a jquery ajax to byte
I have done this one for converting the byte of array in one of

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.