Drawing on image (Multithreading)

This is a discussion on Drawing on image (Multithreading) within the C# Programming forums, part of the General Programming Boards category; hi! i'm coding a raytracer app which uses multiple threads to draw an image. this image is a pictureBox with ...

  1. #1
    Registered User Devils Child's Avatar
    Join Date
    Jan 2008
    Posts
    244

    Drawing on image (Multithreading)

    hi!
    i'm coding a raytracer app which uses multiple threads to draw an image. this image is a pictureBox with a bitmap inside.
    note: every pixel is drawn exactly once!

    yet, i only got trouble because the threads seem to cross. does anybody have an example of two threads drawing an image?

    thanks

  2. #2
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,590
    Not sure about C# thread mechanisms but I'm sure you will need some sort of lock on the image since you would not want two threads altering it at the same time. This might be automatic in C# but it may not be. Reading the .NET Framework SDK might give a little insight as to what you need to do.

  3. #3
    Registered User Devils Child's Avatar
    Join Date
    Jan 2008
    Posts
    244
    i know:
    Code:
    lock(image) {...}
    should solve it, but it doesn't. i still get an exception.

  4. #4
    Registered User valaris's Avatar
    Join Date
    Jun 2008
    Location
    RING 0
    Posts
    507
    What is the exception? Are you trying to alter a UI element from a thread that doesn't own it? If so make sure that each thread is just editing a Bitmap object.

  5. #5
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,235
    If each pixel is drawn exactly once, then there should be no locking necessary or "crossing" of threads. You need to give more details.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  6. #6
    Registered User Devils Child's Avatar
    Join Date
    Jan 2008
    Posts
    244
    well the picturebox and the image is created with the main UI thread, but there are 2 other threads locking and drawing on the bitmap this way:
    CodeProject: Image Processing for Dummies with C# and GDI+ Part 1 - Per Pixel Filters. Free source code and programming help

  7. #7
    Registered User Devils Child's Avatar
    Join Date
    Jan 2008
    Posts
    244
    ok i think i got it now. i have to lock the pixeldata only once.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem reading tiff image files?
    By compz in forum C++ Programming
    Replies: 9
    Last Post: 10-30-2009, 04:17 AM
  2. Replies: 1
    Last Post: 05-27-2009, 12:46 PM
  3. Simple Image Processing
    By ejohns85 in forum C++ Programming
    Replies: 4
    Last Post: 03-19-2009, 12:10 PM
  4. Why only 32x32? (OpenGL) [Please help]
    By Queatrix in forum Game Programming
    Replies: 2
    Last Post: 01-23-2006, 01:39 PM
  5. Replies: 4
    Last Post: 03-02-2003, 08:12 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21