Exemplo n.º 1
0
        public void ProcessPicture(Pulse.Base.PictureBatch pb, string config)
        {
            List <Picture> lp = pb.GetPictures(1);

            if (!lp.Any())
            {
                return;
            }
            Picture p = lp.First();

            ManualResetEvent mre = new ManualResetEvent(false);

            int stepCount = 13;

            //get color to start with
            Color currentAero = Desktop.GetCurrentAeroColor();
            Color endAeroColor;

            //load file
            using (MemoryStream ms = new MemoryStream(File.ReadAllBytes(p.LocalPath)))
            {
                using (Bitmap bmp = (Bitmap)Bitmap.FromStream(ms))
                {
                    //get final color
                    endAeroColor = PictureManager.CalcAverageColor(bmp);
                }
            }

            //build transition
            Color[] transitionColors = CalcColorTransition(currentAero, endAeroColor, stepCount);

            //build timer
            System.Timers.Timer t = new System.Timers.Timer(100);

            int currentStep = 0;

            t.Elapsed += delegate(object sender, System.Timers.ElapsedEventArgs e)
            {
                //double check (I've seen cases where timer fires even though currentStep is past {stepCount}
                if (currentStep >= stepCount)
                {
                    mre.Set(); t.Stop(); return;
                }

                //set to next color
                Desktop.SetDwmColor(transitionColors[currentStep]);

                //increment steps and check if we should stop the timer
                currentStep++;
                if (currentStep >= stepCount)
                {
                    mre.Set(); t.Stop();
                }
            };

            t.Start();

            mre.WaitOne();
        }
Exemplo n.º 2
0
        public void ProcessPicture(PictureBatch pb, string config)
        {
            List <Picture> lp = pb.GetPictures(1);

            if (!lp.Any())
            {
                return;
            }
            Picture p = lp.First();

            //deserialize configuration
            WallpaperSetterSettings wss = null;

            if (!string.IsNullOrEmpty(config))
            {
                wss = WallpaperSetterSettings.LoadFromXML(config);
            }
            else
            {
                wss = new WallpaperSetterSettings();
            }


            //set wallpaper style (tiled, centered, etc...)
            //SetWallpaperType(wss.Position);

            //set desktop background color
            //Code came roughly form http://www.tek-tips.com/viewthread.cfm?qid=1449619
            if (wss.BackgroundColorMode == WallpaperSetterSettings.BackgroundColorModes.Specific)
            {
                int[] aiElements = { WinAPI.COLOR_DESKTOP };
                WinAPI.SetSysColors(1, aiElements, new WinAPI.COLORREF(wss.Color));
            }
            else if (wss.BackgroundColorMode == WallpaperSetterSettings.BackgroundColorModes.Computed)
            {
                using (Bitmap bmp = (Bitmap)Image.FromFile(p.LocalPath)) {
                    int[] aiElements = { WinAPI.COLOR_DESKTOP };
                    WinAPI.SetSysColors(1, aiElements, new WinAPI.COLORREF(PictureManager.CalcAverageColor(bmp)));
                }
            }

            Desktop.SetWallpaperUsingActiveDesktop(p.LocalPath);
        }