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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T20:51:17+00:00 2026-05-21T20:51:17+00:00

I have hex data and I want to convert it to 200×200 pixel grayscale

  • 0

I have hex data and I want to convert it to 200×200 pixel grayscale picture, but I can’t find a way to do it.

Can anyone please show me a way or give me a resource to solve this problem??

  • 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-21T20:51:17+00:00Added an answer on May 21, 2026 at 8:51 pm

    For what you have written (too few) you could create Bitmap bmp = new Bitmap(200,200).
    Then you could use bmp.SetPixel(x,y,color) according to your text data.

    UPDATE:
    Assuming a lot of things:

    • you have a hexstr containing hex data representing your bmp
    • hexstr is made of two chars groups (hex data)
    • every hex data group is 2 or 6 chars long (2 chars if hex val is already a greyscale val, 6 chars if you have a RGB value to convert to grayscale)

    SECOND UPDATE:
    Your file contanins 16×2450=39200 pixel, so your image cannot be 200×200. I assume it’s 200×192.
    This code works, even if I don’t understand what image represents…

    You can try this:

    public Form1()
    {
        InitializeComponent();
        string hexstr = FileToHexStr(path_to_file);
        pictureBox1.Image = ConvertToBmp(hexstr, 200, 196, true);
    }
    
    private string FileToHexStr(string filename)
    {
        StringBuilder sb = new StringBuilder();
        string[] f = File.ReadAllLines(filename);
        foreach (string s in f) sb.Append(s.Trim().Replace(" ", ""));
        return sb.ToString();
    }
    
    private byte[] StringToByteArray(string hex)
    {
        return Enumerable.Range(0, hex.Length)
                         .Where(x => x % 2 == 0)
                         .Select(x => System.Convert.ToByte(hex.Substring(x, 2), 16))
                         .ToArray();
    }
    
    private Bitmap ConvertToBmp(string hexstr, int width, int height, bool isGrayScaleString)
    {
        /// If hexstr is a color bitmap I assume that a single pixel
        /// must be 3 values long (one for R, one for G, one for B);
        /// if not, then every hex value is a pixel
        int bpp = isGrayScaleString ? 1 : 3;
        byte[] hexarr = StringToByteArray(hexstr);
        // Check if string is correct
        if (hexarr.Length != (width * height * bpp)) return null;
    
        Bitmap bmp = new Bitmap(width, height);
        int index = 0;
        for (int i = 0; i < hexarr.Length; i +=  bpp)
        {
            int luma = (int)(isGrayScaleString ?
                hexarr[index] :
                // Formula to convert from RGB to Grayscale
                // <see>http://www.bobpowell.net/grayscale.htm</see>
                0.3 * hexarr[i] + 0.59 * hexarr[i + 1] + 0.11 * hexarr[i + 2]);
            Color c = Color.FromArgb(luma, luma, luma);
            bmp.SetPixel(index % width, index / width, c);
            index++;
        }
        return bmp;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a hex string like: data = 437c2123 I want to convert this
In my application I have a control that displays hex data: I want to
I have some Perl code where the hex() function converts hex data to decimal.
I have some columns with image data type and I want to preview (or
I have problem with encoding data in Oracle database. I want to xor string
I have Hex data as Byte[] data = new Byte[2]; data[0]=FF; data[1]=FF; Here the
How do I convert binary data to hex value in obj-c? Example: 1111 =
how can i convert Hex UTF-8 bytes -E0 A4 A4 to hex code point
I have a one dimensional vector of data in R and I want to
I have a file with binary data and I need to replace a few

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.