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

  • Home
  • SEARCH
  • 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 7965101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T06:03:39+00:00 2026-06-04T06:03:39+00:00

I need some help in converting a hex string into an image doing some

  • 0

I need some help in converting a hex string into an image

doing some researches i came up to this code:

private byte[] HexString2Bytes(string hexString)
{
    int bytesCount = (hexString.Length) / 2;
    byte[] bytes = new byte[bytesCount];
    for (int x = 0; x < bytesCount; ++x)
    {
        bytes[x] = Convert.ToByte(hexString.Substring(x*2, 2),16);
    }

    return bytes;
}


public bool ByteArrayToFile(string _FileName, byte[] _ByteArray)
{
    try
    {
            System.IO.FileStream _FileStream = new  System.IO.FileStream(_FileName, System.IO.FileMode.Create, System.IO.FileAccess.Write);
            _FileStream.Write(_ByteArray, 0, _ByteArray.Length);
            _FileStream.Close();
            return true;
     }
     catch (Exception _Exception)
     {
         MessageBox.Show(_Exception.Message);
     }

        return false;
 }

The problem is that the resulting image is almost all black and i guess i need to apply some filters to better translate the gray-scale (since the original image is in gray-scale only)

Can anyone help me?

Many thanks

  • 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-04T06:03:40+00:00Added an answer on June 4, 2026 at 6:03 am

    You don’t need to apply any filters. I guess that the hexString variable that you are passing as input is simply a black image. The following works great for me:

    class Program
    {
        static void Main()
        {
            byte[] image = File.ReadAllBytes(@"c:\work\someimage.png");
            string hex = Bytes2HexString(image);
    
            image = HexString2Bytes(hex);
            File.WriteAllBytes("visio.png", image);
            Process.Start("visio.png");
        }
    
        private static byte[] HexString2Bytes(string hexString)
        {
            int bytesCount = (hexString.Length) / 2;
            byte[] bytes = new byte[bytesCount];
            for (int x = 0; x < bytesCount; ++x)
            {
                bytes[x] = Convert.ToByte(hexString.Substring(x * 2, 2), 16);
            }
    
            return bytes;
        }
    
        private static string Bytes2HexString(byte[] buffer)
        {
            var hex = new StringBuilder(buffer.Length * 2);
            foreach (byte b in buffer)
            {
                hex.AppendFormat("{0:x2}", b);
            }
            return hex.ToString();
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some help converting a java byte array to a 7-Bit ASCII string.
I need a little help converting some VB.NET code to C#. I have tried
I need some help converting an SQL query into relational algebra. Here is the
I need to convert MimeMessage into byte array, but while converting some characters are
Need some help to solve this. I have a gridview and inside the gridview
Need some help with this problem in implementing with XSLT, I had already implemented
Need some help gathering thoughts on this issue. Our team is moving ahead with
I need some help converting the SQL found below to an equivalent LINQ statement
I need some help in converting my script from using mysql to mysqli I
As already said in the title, I need some help with converting lat/long to

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.