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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:15:10+00:00 2026-05-30T00:15:10+00:00

This is my bitmap creation code public static Bitmap Plot24(ref byte[] bufferArray, int lengthOfBufferArray,

  • 0

This is my bitmap creation code

public static Bitmap Plot24(ref byte[] bufferArray, int lengthOfBufferArray, String fileName)
    {
        int position = 0;      

        int rows = (int)Math.Ceiling((double)lengthOfBufferArray / (3*columns) );

        Bitmap b = new Bitmap(columns , rows, PixelFormat.Format24bppRgb);
        BitmapData bmd = b.LockBits(new Rectangle(0, 0, columns , rows), ImageLockMode.ReadWrite, b.PixelFormat); 

            unsafe
            {
                for (int j = 0; j < rows; j++)
                {                    
                    byte* row = (byte*)bmd.Scan0 + ((j * bmd.Stride) ); 

                    for (int i = 0; i < columns*3; i+=3)
                    {                                                
                        if (position < lengthOfBufferArray)
                        {                                                                         

                            try
                            {
                                row[i+2] = bufferArray[position];
                                position++;
                                if (position < lengthOfBufferArray)
                                {
                                    row[i+1] = bufferArray[position];
                                    position++;
                                }
                                else
                                {                                   
                                    break;                                       
                                }

                                if (position < lengthOfBufferArray)
                                {
                                    row[i] = bufferArray[position];
                                    position++;
                                }
                                else
                                {                                       
                                    break;                               
                                }
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine(e.ToString());

                            }
                        }
                    }
                }

                b.UnlockBits(bmd);

                return b;
            } 
    }

And this is how i save the returned bitmap

 b.Save(outputFilename, ImageFormat.Bmp);

When i have all FF hexadecimals in the bufferArray still the white pixels are not that white.

And when i have random values in the bufferArray other colors also look like they are washed away.

How can i make it save in the normal brightness level ?

  • 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-30T00:15:13+00:00Added an answer on May 30, 2026 at 12:15 am

    I tested your sample code and it worked just fine. I have an excerpt of you sample at the bottom of mine with some slight modification to the method parameters.

    Could you supply in your question a sample of how you use your Plot24 method? Maybe the problem lies there.

        void Main()
        {
            int rows = 100;
            int columns = 100;
    
            var random = new Random(DateTime.Now.Ticks.GetHashCode());
    
            byte[] bytes = Enumerable
                .Range(0, columns * rows)
    
                // White
                .SelectMany(i => new[] { (byte)0xFF, (byte)0xFF, (byte)0xFF, } )
    
                // Random
                /*.SelectMany(i => 
                    {
                        byte[] buffer = new byte[3];
                        random.NextBytes(buffer);
                        return buffer; 
                    })*/
    
                .ToArray();
    
            using (var bm = Plot24(ref bytes, columns))
            {
                bm.Save(@"c:\test.bmp", ImageFormat.Bmp);
            }
        }
    
        public static Bitmap Plot24(ref byte[] bufferArray, int columns)
        {
            int position = 0;      
            int lengthOfBufferArray = bufferArray.Length;
    
            int rows = (int)Math.Ceiling((double)lengthOfBufferArray / (3*columns) );
            // ... the rest of your code is just fine
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, this code does not actually draw my bitmap file... or show
i have a code like this Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.correct); newImg = (ImageView)findViewById(R.id.rwans);
I try do this: Bitmap bitmapOrg = BitmapFactory.decodeFile(/sdcard/+ photoName + .jpg); int width =
This may be a repeat of the following unanswered question: Help with bitmap lock
LearnWPF.com posted this article about converting bitmap images to XAML and using them in
I found this example and used it How do you resize a Bitmap under
I have a bitmap image context and want to let this appear blurry. So
Given a loaded Bitmap object. I want to slice up this image into 256x256
I'm drawing a String with g.DrawString on an image. Before I'm doing this I'm
In my project I have a bitmap filling the entire screen. On this bitmap

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.