Ejemplo n.º 1
0
        private void Bw_DoWork(object sender, DoWorkEventArgs e)
        {
            BackgroundWorker me = sender as BackgroundWorker;

            int[]             a    = new int[LedsPerStrip * StripCount];
            TransformedBitmap tbmp = null;

            System.Drawing.Color[,] grid = new System.Drawing.Color[StripCount, LedsPerStrip];

            while (!me.CancellationPending)
            {
                if (width == 0)
                {
                    viewport_border.Dispatcher.Invoke(() =>
                    {
                        PresentationSource source = PresentationSource.FromVisual(this);
                        width  = (int)(viewport.ActualWidth * source.CompositionTarget.TransformToDevice.M11);
                        height = (int)(viewport.ActualHeight * source.CompositionTarget.TransformToDevice.M22);
                        if (width != 0)
                        {
                            rtb = new RenderTargetBitmap(width, height, 96.0, 96.0, PixelFormats.Pbgra32);
                        }
                    });
                    Thread.Sleep(33);
                    continue;
                }

                viewport_border.Dispatcher.Invoke(() =>
                {
                    rtb.Render(viewport_border);
                    double scalex = LedsPerStrip * 1.0 / width;
                    double scaley = StripCount * 1.0 / height;
                    tbmp          = new TransformedBitmap(rtb, new ScaleTransform(scalex, scaley));
                    tbmp.CopyPixels(a, 4 * LedsPerStrip, 0);
                });

                for (int i = 0; i < StripCount; i++)
                {
                    for (int j = 0; j < LedsPerStrip; j++)
                    {
                        grid[i, j] = System.Drawing.Color.FromArgb(a[i * LedsPerStrip + j]);
                    }
                }

                _ledWall.SetWall(grid);

                Thread.Sleep(33);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Sets entire wall to a single color
        /// </summary>
        /// <param name="c"></param>
        private void setWallSolidColor(Color c)
        {
            Color[,] grid = new Color[StripCount, LedsPerStrip];
            for (int i = 0; i < grid.GetLength(0); i++)
            {
                for (int j = 0; j < grid.GetLength(1); j++)
                {
                    grid[i, j] = c;
                }
            }
            _ledWall.SetWall(grid);

            //TODO: use "set entire wall" message instead of entire grid
            //_ledWall.SetWall(c);
        }
Ejemplo n.º 3
0
        private void takeScreenshot(Object state)
        {
            //Create a new bitmap if necessary
            if (frames[frame_idx % frames.Length] == null)
            {
                frames[frame_idx % frames.Length] = new Bitmap(CapturedScreen.Bounds.Width, CapturedScreen.Bounds.Height, PixelFormat.Format32bppArgb);
            }
            Bitmap frame = frames[frame_idx % frames.Length];

            // Create a graphics object from the bitmap.
            var gfxScreenshot = Graphics.FromImage(frame);

            // Take the screenshot from the upper left corner to the right bottom corner.
            gfxScreenshot.CopyFromScreen(CapturedScreen.Bounds.X, CapturedScreen.Bounds.Y, 0, 0, CapturedScreen.Bounds.Size, CopyPixelOperation.SourceCopy);

            Bitmap output = new Bitmap(frame, new Size(LedsPerStrip, StripCount));

            Bmp2Grid(grid, output);

            _ledWall.SetWall(grid);
        }