Example #1
0
        public void writeColouredToFile(Pair <int, int> XY, int elems, MyBitmap bmp)
        {
            int row  = XY.First;
            int col  = XY.Second;
            int done = 0;

            while (done < elems && row < height)
            {
                //Bitmap bitmap = new Bitmap(bmp);
                if (col == width)
                {
                    col = 0;
                    row++;
                    if (row == height)
                    {
                        break;
                    }
                }
                Color rgb = new Color();
                rgb = Color.FromArgb(rValues[row][col], gValues[row][col], bValues[row][col]);
                bmp.SetPixel(col, row, rgb);
                done++;
                col++;
                //bmp = bitmap;
            }
        }
Example #2
0
        public void writeToFile(string path)
        {
            int elemPerThr             = (width * height) / Program.nr_threads;
            int ord                    = 1;
            List <Task <bool> > tasks  = new List <Task <bool> >();
            MyBitmap            bitmap = new MyBitmap(width, height);

            for (int i = 0; i < Program.nr_threads; i++)
            {
                if (i + 1 == Program.nr_threads)
                {
                    elemPerThr += (width * height) % Program.nr_threads;
                }
                Pair <int, int> XY = getXY(width, ord);
                int             finalElemPerThr = elemPerThr;
                tasks.Add(Task.Factory.StartNew(() =>
                {
                    writeColouredToFile(XY, finalElemPerThr, bitmap);
                    return(true);
                }));
                ord += elemPerThr;
            }
            Bitmap bmp = new Bitmap(bitmap.Bitmap);

            bmp.Save(path);
        }