CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    May 2011
    Posts
    19

    [RESOLVED] Writing image data to disk in parallel?

    So I actually posted my question to StackOverflow, but did not really get an answer.

    Basically, I want to write an image to disk in parallel with an algorithm that is processing that same image. The code is really simple:
    Code:
    string ProcessImage(System::Drawing::Bitmap ^bmp, System::String^ targetFile)
    {
        bmp->Save(targetFile);
        System::Drawing::Bitmap^ bmp8 = BitmapConvertPixelFormat(bmp, 8); //<-- a function I wrote which converts the 32bpp I am passed into an 8bpp one
        string results = Analyze(bmp8); //<--- takes a good bit of time
        return results;
    }

    What would be the fastest way to do this? Please let me know of any libraries you recommend with a code sample. I would prefer one that is within .NET or native C++ just to avoid having to link into many different libraries.

    Thanks in advance!

  2. #2
    Join Date
    Jan 2009
    Posts
    596

    Re: Writing image data to disk in parallel?

    How much time do you expect to save by doing this? The most you could save would be the smaller of (Time to save file) and (Time to process bitmap). In your case (Time to save file) will be much less than (Time to process bitmap), so the user wouldn't really notice any improvement anyway.

    Could you put some code in to time these two parts so you know how much improvement you could make?

  3. #3
    Join Date
    Jul 2005
    Location
    Netherlands
    Posts
    2,042

    Re: Writing image data to disk in parallel?

    First of all, why did you post this in the Non Visual C++ section? Since you are using C++/CLI, you should have posted it here.
    Quote Originally Posted by Amil View Post
    Basically, I want to write an image to disk in parallel with an algorithm that is processing that same image. The code is really simple:
    Code:
    string ProcessImage(System::Drawing::Bitmap ^bmp, System::String^ targetFile)
    {
        bmp->Save(targetFile);
        System::Drawing::Bitmap^ bmp8 = BitmapConvertPixelFormat(bmp, 8); //<-- a function I wrote which converts the 32bpp I am passed into an 8bpp one
        string results = Analyze(bmp8); //<--- takes a good bit of time
        return results;
    }
    Since both the saving and processing only reads the bitmap bmp, you can just send the saving off to a different thread. Since you are already using .Net, I suggest using ThreadPool::QueueUserWorkItem.
    Cheers, D Drmmr

    Please put [code][/code] tags around your code to preserve indentation and make it more readable.

    As long as man ascribes to himself what is merely a posibility, he will not work for the attainment of it. - P. D. Ouspensky

  4. #4
    Join Date
    Jan 2009
    Posts
    1,689

    Re: Writing image data to disk in parallel?

    Uh... am I missing something? That's not C++. What do you think the ^ operator is?

  5. #5
    Join Date
    May 2011
    Posts
    19

    Re: Writing image data to disk in parallel?

    Thanks for the responses. I guess I'll first time the save and processing of the bitmap. I'll also look into using ThreadPool::QueueUserWorkItem like D_Drmmr suggested.

    Also, if a moderator could move this into the C++/CLI section, please do so. I wasn't sure where to post this at first as I thought the concept of C++ multi-threading was general enough to go in either section.

    EDIT: I got it working with ThreadPool::QueueUserWorkItem! Preventing race conditions was a bit tricky, but I found this interface really easy-to-use for threading.
    Last edited by Amil; April 21st, 2012 at 11:15 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured