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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:42:00+00:00 2026-05-13T09:42:00+00:00

This code is for transforming from colored to black and white. I tried to

  • 0

This code is for transforming from colored to black and white.

  • I tried to add parallel section to the code
  • just transforming from gray-scale to black-white
  • i tried to assign to each thread a number of cols which has amount of pixels

but the performance didnt improve at all.

I tried for a 800*600 image by changing the divisor value (its here 800 in code) in the 2 for loops and the counter value increment .

This change should make the number of threads increase or decrease

the results :

value |  num of thread |   time
 800       1              1.17 sec
 400       2              1.17 sec
 200       4              1.17 sec
and so on ...

Help me to increase the performance coz it takes 8 sec for bigger images and i want to make it parallel

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using System.Threading;

namespace IMG
{

public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }
    string path = "";
    public void openimage()
    {
        if (openFileDialog1.ShowDialog() == DialogResult.OK)
        {
            path = openFileDialog1.FileName;
        }
    }
    Bitmap bm;
    Bitmap gs;
    private void button1_Click(object sender, EventArgs e)
    {
        if (path == "")
        {
            openimage();
        }
        Graphics g = this.CreateGraphics();
        bm = new Bitmap(path);
        // Draw image with no effects.....
        g.DrawImage(bm, 100, 100, 200, 200);
        gs = new Bitmap(bm.Width, bm.Height);
        worker soso = new worker(gs, bm);
        worker.counter = 0;
        soso.tograyscale();
        // Draw gray image.......
        g.DrawImage(gs, 305, 100, 200, 200);
        DateTime x = DateTime.Now;
        for (int koko = 0; koko < gs.Width/400; koko++)
        {        
                Thread t1 = new Thread(new ThreadStart(soso.trasform));
                t1.Start();
                t1.Join();
                soso.increment();
        }
        g.DrawImage(bm, 510, 100, 200, 200);
        gs.Dispose();
        g.Dispose();
        textBox19.Text=(DateTime.Now - x).ToString();
    }
}
public class worker
{
    public static int counter = 0;
    public Bitmap gs;
    public Bitmap bm;
    public int xxxx;
    public worker(Bitmap a, Bitmap b)
    {
        gs = a;
        bm = b;
        xxxx = a.Height;
    }
    public void increment()
    {
        counter += 400;
    }
    public void trasform()
    {
        argtransform(counter);

    }
    public void tograyscale()
    {
        for (int i = 0; i < bm.Width; i++)
        {
            for (int j = 0; j < bm.Height; j++)
            {
                Color c = bm.GetPixel(i, j);
                int y = (int)(0.3 * c.R + 0.59 * c.G + 0.11 * c.B);
                gs.SetPixel(i, j, Color.FromArgb(y, y, y));
            }
        }
    }
    public void argtransform(int cc)
    {
        for (int i = cc; i < cc + 400; i++)
        {
            for (int j = 0; j < xxxx; j++)
            {
                Color c = gs.GetPixel(i, j);
                int y1 = 0;
                if (c.R >= 128)
                    y1 = 255;
                bm.SetPixel(i, j, Color.FromArgb(y1, y1, y1));
            }
        }
    }
  }
}

thank you please as soon as u can


thank you all
question for Craig Stuntz : how could i edit the color of pixel without calling setpixel ?
thank you for your help

  • 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-13T09:42:00+00:00Added an answer on May 13, 2026 at 9:42 am

    By calling Thread.Start then immediately calling Thread.Join, you’re effectively working in serial rather than parallel. Place a second loop after the Thread.Start loop which calls Thread.Join.

    List<Thread> threads = new List<Thread>();
    for (int koko = 0; koko < gs.Width/400; koko++)
    {        
        Thread t1 = new Thread(new ThreadStart(soso.trasform));
        t1.Start();
        threads.Add(t1);
        soso.increment();
    }
    
    foreach (Thread thread in threads) thread.Join();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 285k
  • Answers 285k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer VS2010 does have that with PLINQ. Using the extensions AsParallel().WithDegreeOfParallelism(nbProcessors)… May 13, 2026 at 4:38 pm
  • Editorial Team
    Editorial Team added an answer you can find a column in GridView.Columns and then use… May 13, 2026 at 4:38 pm
  • Editorial Team
    Editorial Team added an answer The example in Chandru's answer looks like a lot of… May 13, 2026 at 4:38 pm

Related Questions

I am running into the same problem as in this question: How do you
We've got a mature body of code that loads data from files into a
The executeTime below is 30 seconds the first time, and 25 seconds the next
I'm trying to use a BULK INSERT statement to populate a large (17-million-row) table
Code: if ( $_GET['tab'] == 'newest' ) { // Go through each question foreach(

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.