示例#1
0
 private void initLEDs()
 {
     sColors = new ScreenColors();
     //aColors = new AudioColors();
     if (LEDSetup.Setup() == null)
     {
         Logger.QueueLine("No active Adalight controller detected");
         Dispatcher.BeginInvoke(new Action(() => { MessageBox.Show("No active Adalight controller detected"); }));
     }
     else
     {
         Logger.QueueLine("Starting LED draw timer");
         DrawTimer          = new System.Timers.Timer(1000.0 / 30.0);
         DrawTimer.Elapsed += DrawTimer_Elapsed;
         DrawTimer.Start();
     }
 }
示例#2
0
 private void buttonSwitch_Click(object sender, RoutedEventArgs e)
 {
     if (CurrentMode == LEDMode.Screen)
     {
         Logger.QueueLine("Switching LED Mode: Audio");
         CurrentMode = LEDMode.Audio;
         DrawTimer.Stop();
         aColors = new AudioColors();
         sColors.Dispose();
         sColors = null;
         buttonSwitch.Content = "_Switch to Screen";
     }
     else if (CurrentMode == LEDMode.Audio)
     {
         Logger.QueueLine("Switching LED Mode: Screen");
         CurrentMode = LEDMode.Screen;
         aColors.wi.StopRecording();
         sColors = new ScreenColors();
         aColors = null;
         DrawTimer.Start();
         buttonSwitch.Content = "_Switch to Audio";
     }
 }
示例#3
0
        private void drawLEDsColor()
        {
            var screenBitmap = ScreenColors.getScreenGDI(0);

            BitmapImage bitmapImage = new BitmapImage();

            using (MemoryStream memory = new MemoryStream())
            {
                screenBitmap.Save(memory, System.Drawing.Imaging.ImageFormat.Bmp);
                memory.Position = 0;
                bitmapImage.BeginInit();
                bitmapImage.StreamSource = memory;
                bitmapImage.CacheOption  = BitmapCacheOption.OnLoad;
                bitmapImage.EndInit();
            }
            var bgBrush = new ImageBrush();

            bgBrush.ImageSource     = bitmapImage;
            borderScreen.Background = bgBrush;

            foreach (var led in LEDSetup.leds)
            {
                int  r = 0, g = 0, b = 0, c = 0;
                long re = 0, gr = 0, bl = 0;
                for (int x = (int)led.Coords.Left; x < (int)led.Coords.Right; x += 10)
                {
                    for (int y = (int)led.Coords.Top; y < (int)led.Coords.Bottom; y += 10)
                    {
                        System.Drawing.Color col;
                        lock (screenBitmap)
                        {
                            col = screenBitmap.GetPixel(x, y);
                        }
                        re += (long)(col.R * col.R);
                        gr += (long)(col.G * col.G);
                        bl += (long)(col.B * col.B);
                        c++;
                    }
                }
                r = (int)Math.Sqrt(re / c);
                g = (int)Math.Sqrt(gr / c);
                b = (int)Math.Sqrt(bl / c);
                if (r > 255)
                {
                    r = 255;
                }
                if (g > 255)
                {
                    g = 255;
                }
                if (b > 255)
                {
                    b = 255;
                }

                Border br = new Border();
                br.BorderBrush     = Brushes.Black;
                br.BorderThickness = new Thickness(1);
                br.Background      = new SolidColorBrush(new Color()
                {
                    A = 255, R = (byte)r, G = (byte)g, B = (byte)b
                });
                br.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
                br.VerticalAlignment   = System.Windows.VerticalAlignment.Top;
                br.Height = led.Coords.Height * scaleFactor;
                br.Width  = led.Coords.Width * scaleFactor;
                br.Margin = new Thickness(led.Coords.X * scaleFactor, led.Coords.Y * scaleFactor, 0, 0);
                gridScreenRep.Children.Add(br);
            }

            //screenBitmap.Dispose();
        }