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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:08:51+00:00 2026-05-27T17:08:51+00:00

for (int x = 0; x < blockCountX; x++) { for (int y =

  • 0
                    for (int x = 0; x < blockCountX; x++)
                    {
                        for (int y = 0; y < blockCountY; y++)
                        {
                            //get blocks from image to new image and send to threaded processor
                            imageBlocks[x, y] = image.Clone(clipRectangle, System.Drawing.Imaging.PixelFormat.Format8bppIndexed);
                            System.Threading.Thread t = new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(ThreadedFromHeightMap));
                            t.Start(imageBlocks[x,y]);
                            clipRectangle.Offset(0, IMAGEBLOCKSIZE);
                        }
                        clipRectangle.Offset(IMAGEBLOCKSIZE, clipRectangle.Location.Y * -1);
                    }
                    break;
            }
        }
        private void ThreadedFromHeightMap(object Image)
        {
            Bitmap image = (Bitmap)Image;
            int width = image.Width;
            int height = image.Height;

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    map.Hexes.Add(new Point(x, y), new Hex(image.GetPixel(x, y).B));
                    //tempHexes.Enqueue(new Hex(image.GetPixel(x, y).B));
                }
            }
        }

I’m trying to take pixel data from a 2048 x 2048 8bpp grayscale heightmap and building a hex map with corresponding height values. I’m storing the hexes in a Dictionary collection. All told there’s ~4 million hexes in the collection.

To do this efficiently I’m breaking the image up into 256 x 256 chunks and passing that image to another thread which will parse it and add the hexes to the collection. This is were it all goes haywire. Instead of one image with (0,0) as its top left corner, I now have 64 image chunks that have (0,0) as their top left corner. However I’m using the pixel location as an index for the dictionary. This crashes when the second thread tries to add another value with index (0,0).

How do I mitigate this problem? I’ve thought about building a class that just has an image member and a chunk number member and pass that to the thread so I can adjust the pixel location depending on what chunk the thread is working on but that seems less than optimal.

(I realize the Dictionary I’m using isn’t thread safe. I’ve since fixed that.)

  • 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-27T17:08:52+00:00Added an answer on May 27, 2026 at 5:08 pm

    May I recommend a few things?

    1. Forget about image.GetPixel(), which is horribly slow; work directly with the bitmap data, and the performance of your algorithm will improve by so much, that you will not need to run parallel threads to improve its efficiency. See MSDN: http://msdn.microsoft.com/en-us/library/system.drawing.imaging.bitmapdata.aspx

    2. If you insist on parallel threads, make use of the threadpool, instead of spawning 64 threads. (See MSDN: http://msdn.microsoft.com/en-us/library/3dasc8as(v=vs.80).aspx)

    3. If you insist on spawning many threads, do NOT spawn more threads than the cores of your CPU. I do not suppose you have 64 cores on your machine, do you?

    4. If you insist on spawning many threads, you will, of course, need to pass the location of each tile to the thread, so that you know exactly where that tile should be placed when you reconstruct the big picture. That’s not less than optimal, it is necessary.

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

Sidebar

Related Questions

int placement[] = new int[8]; int placeQueen(int row) { if(row == 8) { printBoard();
int i =132; byte b =(byte)i; System.out.println(b); Mindboggling. Why is the output -124 ?
int numcells = 2; foreach (System.IO.FileInfo fi in fileQuery) { Label1.Text = fileList.Count().ToString(); TableRow
int queryVector = 1; double similarity = 0.0; int wordPower; String[][] arrays = new
int[] x = new int [] { 1, 2, 3}; int[] y = new
int[][] myArray = new int[10][]; foreach (int[] eachArray in myArray) { eachArray = new
int* HT; int HTc = 500; HT = new int[HTc] = {-1}; //Fill array
int x = n / 3; // <-- make this faster // for instance
int x; printf(hello %n World\n, &x); printf(%d\n, x);
int[] mylist = { 2, 4, 5 }; IEnumerable<int> list1 = mylist; list1.ToList().Add(1); //

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.