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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:12:00+00:00 2026-06-14T13:12:00+00:00

I am receiving an image from an external system in the form of a

  • 0

I am receiving an image from an external system in the form of a sequence of BGR values followed by an empty byte. The sequence looks sort of like…

[B,G,R,0,B,G,R,0,…,B,G,R,0] where each BGR0 is a single pixel in an image.

I need this in a .NET Bitmap so I can perform some manipulations on it and have come up with the following function to do so:

    private Bitmap fillBitmap(byte[] data, int width, int height)
    {
        Bitmap map = new Bitmap(width, height);
        for (int i = 0; i < data.Length; i += 4)
        {
            int y = ((i / 4) / width);
            int x = ((i / 4) - (y * width));
            int b = data[i];
            int g = data[i + 1];
            int r = data[i + 2];
            Color pixel = Color.FromArgb(r, g, b);
            map.SetPixel(x, y, pixel);
        }
        return map;
    }

This would normally be ok except that most of my images are 1920×1200… so I have a loop that’s iterating over 2 million times. Even then that wouldn’t be so bad as 2 million iterations shouldn’t be very taxing on any modern processor.

But for some reason, this loop can take upwards of 5-15 seconds to run on a pretty beefy Xeon on my server. It would be trivial to parallelize the loop but I suspect there is an even better way of going about this. Any help would be greatly appreciated!

  • 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-14T13:12:02+00:00Added an answer on June 14, 2026 at 1:12 pm

    The description of the Bitmap.LockBits Method says,

    You can change the color of an image with the SetPixel method, although the LockBits method offers better performance for large-scale changes.

    An alternative, I’d guess, might be to use the Bitmap(Stream) Constructor, after you create a Stream which matches the file format of a bitmap.

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

Sidebar

Related Questions

I'm receiving from socket communication an image as byte[] and then I try to
I am receiving an image, title and description from a json file and i
I am receiving content from a JSON call and I would like to populate
My webserver is receiving image data from an iOS App via HTTP POST. The
I have to upload a base64 encoded image that i am receiving from android
I'm retriving image from a IO file manager (one's installed). Anyhow when I try
I'm retreiving images from a web server directory like this: WebClient webClientImgDownloader = new
I have problem with receiving an image over TCP socket [.net 4.0] Server: Socket
I have a web server which receives an image from a client and do
I am receiving images from xml feed they are very large in size how

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.