Example #1
0
        /// <summary>
        /// The background worker which draws the bitmap, without freezing the GUI thread.
        /// Also updates the progress bar.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void imageDrawer_DoWork(object sender, DoWorkEventArgs e)
        {
            drawParams plotData   = e.Argument as drawParams;
            Bitmap     temp       = new Bitmap(plotData.bredde, plotData.højde);
            LockBitmap lockBitmap = new LockBitmap(temp);

            lockBitmap.LockBits();
            //int[,] xy = plotData.rawData;
            int[,] xy = createData(plotData.rawData, plotData.radius);
            int   max   = xy.Cast <int>().Max();
            Color farve = Color.Black;
            int   count = 0;
            int   done  = bredde * højde;

            for (int i = 0; i < bredde; i++)
            {
                for (int k = 0; k < højde; k++)
                {
                    imageDrawer.ReportProgress((count * 100) / done);
                    count++;
                    if (xy[i, k] != 0)
                    {
                        farve = getColor(xy[i, k], max, plotData.off);
                        //Color farve = Color.Red;
                    }
                    else
                    {
                        farve = Color.Black;
                    }
                    lockBitmap.SetPixel(i, k, farve);
                }
            }
            lockBitmap.UnlockBits();
            e.Result = temp;
        }
Example #2
0
        /// <summary>
        /// Begins the drawing of the heatmap from the current values
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void draw_Click(object sender, EventArgs e)
        {
            rad.Enabled    = false;
            offset.Enabled = false;

            drawParams para = new drawParams()
            {
                rawData = XY,
                bredde  = bredde,
                højde   = højde,
                radius  = (int)rad.Value,
                off     = (int)offset.Value
            };

            imageDrawer.RunWorkerAsync(para);
        }