예제 #1
0
        private static Rectangle GetLegendaRect(Graphics monitorGraphics, ScaledScreen scaledScreen)
        {
            float textScale = scaledScreen.Scale;

            return(new Rectangle(
                       (int)monitorGraphics.VisibleClipBounds.Width - (int)(400 * textScale)
                       - scaledScreen.TaskbarRightWidth,
                       (int)monitorGraphics.VisibleClipBounds.Height - (int)(100 * textScale)
                       - scaledScreen.TaskbarBottomHeight
                       ,
                       (int)(400 * textScale),
                       (int)(100 * textScale)));
        }
예제 #2
0
        private static void DrawTestLegenda(Graphics monitorGraphics, ScaledScreen scaledScreen)
        {
            // outine text
            // http://www.codeproject.com/Articles/42529/Outline-Text#singleoutline1
            System.Drawing.Pen        redPen    = new System.Drawing.Pen(System.Drawing.Color.Red, 6);
            System.Drawing.Pen        yellowPen = new System.Drawing.Pen(System.Drawing.Color.Yellow, 2);
            System.Drawing.SolidBrush brush     = new System.Drawing.SolidBrush(System.Drawing.Color.Blue);

            monitorGraphics.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            monitorGraphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;

            Rectangle legendaRect = new Rectangle((int)400, (int)400, 400, 400);

            System.Drawing.StringFormat stringFormat = (StringFormat)StringFormat.GenericDefault.Clone();
            stringFormat.Trimming = StringTrimming.EllipsisPath;
            System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
            path.AddString("PhotoDesktop",
                           FontFamily.GenericSansSerif,
                           (int)FontStyle.Regular,
                           40,
                           new Rectangle(legendaRect.X, legendaRect.Y, legendaRect.Width, 80),
                           stringFormat);
            path.AddString(string.Format("Scale {0}", scaledScreen.Scale),
                           FontFamily.GenericSansSerif,
                           (int)FontStyle.Regular,
                           20,
                           new Rectangle(legendaRect.X, legendaRect.Y + 80, legendaRect.Width, 20),
                           stringFormat);
            path.AddString(string.Format("{0} x {1}", scaledScreen.Width, scaledScreen.Height),
                           FontFamily.GenericSansSerif,
                           (int)FontStyle.Regular,
                           20,
                           new Rectangle(legendaRect.X, legendaRect.Y + 100, legendaRect.Width, 20),
                           stringFormat);


            Color textColor = Color.FromArgb(0, 0, 0);
            Color glowColor = Color.FromArgb(255, 255, 255);
            float glowScale = 1.0F;

            GlowText(monitorGraphics, path, textColor, glowColor, glowScale);
        }
예제 #3
0
        public static void CreateTestBackgroundImage()
        {
            var result = ScaledScreen.GetPerMonitorDPIAware();

            if (result != ScaledScreen.PROCESS_DPI_AWARENESS.PROCESS_PER_MONITOR_DPI_AWARE)
            {
                ScaledScreen.SetPerMonitorDPIAware();
            }

            ScaledScreen[] scaledScreens = ScaledScreen.AllScaledScreens;


            //using (var virtualScreenBitmap = new Bitmap(ScaledScreen.DesktopRectangle.Width, ScaledScreen.DesktopRectangle.Height))
            using (var virtualScreenBitmap = CreateScreenBitmap(scaledScreens))
            {
                using (var virtualScreenGraphic = Graphics.FromImage(virtualScreenBitmap))
                {
                    // for each screen
                    foreach (var scaledScreen in scaledScreens)
                    {
                        // get drawing ground
                        var monitorBitmap   = new Bitmap(scaledScreen.Width, scaledScreen.Height);
                        var monitorGraphics = Graphics.FromImage(monitorBitmap);

                        // standard background
                        monitorGraphics.FillRectangle(SystemBrushes.Desktop, 0, 0, monitorBitmap.Width, monitorBitmap.Height);

                        // draw background cross
                        Pen boundsCrossPen = new Pen(Color.Red, 4);
                        monitorGraphics.DrawLine(boundsCrossPen,
                                                 new Point(
                                                     0,
                                                     0),
                                                 new Point(
                                                     monitorBitmap.Width,
                                                     monitorBitmap.Height));
                        monitorGraphics.DrawLine(boundsCrossPen,
                                                 new Point(
                                                     monitorBitmap.Width,
                                                     0),
                                                 new Point(
                                                     0,
                                                     monitorBitmap.Height));

                        // draw workarea cross
                        Pen workareaCrossPen = new Pen(Color.Green, 4);
                        monitorGraphics.DrawLine(workareaCrossPen,
                                                 new Point(
                                                     scaledScreen.UnscaledWorkingArea.X,
                                                     scaledScreen.UnscaledWorkingArea.Y),
                                                 new Point(
                                                     scaledScreen.UnscaledWorkingArea.Width + scaledScreen.UnscaledWorkingArea.X,
                                                     scaledScreen.UnscaledWorkingArea.Height + scaledScreen.UnscaledWorkingArea.Y));
                        monitorGraphics.DrawLine(workareaCrossPen,
                                                 new Point(
                                                     scaledScreen.UnscaledWorkingArea.Width + scaledScreen.UnscaledWorkingArea.X,
                                                     scaledScreen.UnscaledWorkingArea.Y),
                                                 new Point(
                                                     scaledScreen.TaskbarLeftWidth,
                                                     scaledScreen.UnscaledWorkingArea.Height + scaledScreen.UnscaledWorkingArea.Y));


                        // https://code.msdn.microsoft.com/DPI-Tutorial-sample-64134744/sourcecode?fileId=86763&pathId=1297537410
                        Font font = new Font(FontFamily.GenericSansSerif, (int)((float)10 * scaledScreen.Scale));
                        monitorGraphics.DrawString(scaledScreen.DeviceName, font, Brushes.LightBlue,
                                                   new PointF(scaledScreen.TaskbarLeftWidth + 10 * scaledScreen.Scale,
                                                              scaledScreen.TaskbarTopHeight + 10 * scaledScreen.Scale));

                        monitorGraphics.DrawString(scaledScreen.DeviceName, font, Brushes.LightGreen,
                                                   new PointF(scaledScreen.TaskbarLeftWidth + scaledScreen.UnscaledWorkingArea.Width - 200 * scaledScreen.Scale,
                                                              scaledScreen.TaskbarTopHeight + scaledScreen.UnscaledWorkingArea.Height - 50 * scaledScreen.Scale));

                        DrawTestLegenda(monitorGraphics, scaledScreen);

                        Rectangle rectangle = new Rectangle(scaledScreen.UnscaledBounds.X - ScaledScreen.DesktopRectangle.X, scaledScreen.UnscaledBounds.Y - ScaledScreen.DesktopRectangle.Y, scaledScreen.UnscaledBounds.Width, scaledScreen.UnscaledBounds.Height);

                        virtualScreenGraphic.DrawImage(monitorBitmap, rectangle);
                    }

                    virtualScreenBitmap.Save(WallpaperPath + defaultBackgroundFileName, ImageFormat.Bmp);
                }
            }

            SystemParametersInfo(SPI_SETDESKWALLPAPER, 0u, WallpaperPath + defaultBackgroundFileName, SPIF_UPDATEINIFILE);
        }
예제 #4
0
        private static void DrawLegenda_orig(Graphics monitorGraphics, ScaledScreen scaledScreen, DesktopImage imageData)
        {
            // outine text
            // http://www.codeproject.com/Articles/42529/Outline-Text#singleoutline1
            //System.Drawing.Pen redPen = new System.Drawing.Pen(System.Drawing.Color.Red, 6);
            //System.Drawing.Pen yellowPen = new System.Drawing.Pen(System.Drawing.Color.Yellow, 2);
            //System.Drawing.SolidBrush brush = new System.Drawing.SolidBrush(System.Drawing.Color.Blue);

            monitorGraphics.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            monitorGraphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;

            float textScale = scaledScreen.Scale;

            Rectangle legendaRect = new Rectangle(
                (int)monitorGraphics.VisibleClipBounds.Width - (int)(400 * textScale)
                - scaledScreen.TaskbarRightWidth,
                (int)monitorGraphics.VisibleClipBounds.Height - (int)(100 * textScale)
                - scaledScreen.TaskbarBottomHeight
                ,
                (int)(400 * textScale),
                (int)(100 * textScale));

            System.Drawing.StringFormat stringFormat = (StringFormat)StringFormat.GenericDefault.Clone();
            stringFormat.Trimming = StringTrimming.EllipsisPath;
            System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
            path.AddString(imageData.Filename,
                           FontFamily.GenericSansSerif,
                           (int)FontStyle.Regular,
                           (int)(20 * textScale),
                           new Rectangle(legendaRect.X, legendaRect.Y, legendaRect.Width, (int)(20 * textScale)),
                           stringFormat);
            path.AddString(imageData.DisplayFolder,
                           FontFamily.GenericSansSerif,
                           (int)FontStyle.Regular,
                           (int)(25 * textScale),
                           new Rectangle(legendaRect.X, legendaRect.Y + (int)(20 * textScale), legendaRect.Width, (int)(25 * textScale)),
                           stringFormat);
            path.AddString(string.Format("{0} x {1}", imageData.Image.Width, imageData.Image.Height),
                           FontFamily.GenericSansSerif,
                           (int)FontStyle.Regular,
                           (int)(16 * textScale),
                           new Rectangle(legendaRect.X, legendaRect.Y + (int)(50 * textScale), legendaRect.Width, (int)(16 * textScale)),
                           stringFormat);

            // search for date taken
            DateTime dateTaken = DateTime.Now;

            foreach (PropertyItem propItem in imageData.Image.PropertyItems)
            {
                if (propItem.Id == PropertyTagExifDTOrig)
                {
                    string dateTakenString = dateRegex.Replace(Encoding.UTF8.GetString(propItem.Value), "-", 2);
                    dateTaken = DateTime.Parse(dateTakenString);
                }
            }

            path.AddString(dateTaken.ToString("dd-MM-yyyy hh:mm"),
                           FontFamily.GenericSansSerif,
                           (int)FontStyle.Regular,
                           (int)(20 * textScale),
                           new Rectangle(legendaRect.X, legendaRect.Y + (int)(70 * textScale), legendaRect.Width, (int)(20 * textScale)),
                           stringFormat);


            //monitorGraphics.DrawPath(redPen, path);
            //monitorGraphics.DrawPath(yellowPen, path);
            //monitorGraphics.FillPath(brush, path);

            Color textColor = Color.FromArgb(255, 255, 255);
            Color glowColor = Color.FromArgb(0, 0, 0);
            //Color textColor = Color.FromArgb(0, 0, 0);
            //Color glowColor = Color.FromArgb(255, 255, 255);
            float glowScale = 1.0F;

            GlowText(monitorGraphics, path, textColor, glowColor, glowScale);
        }
예제 #5
0
        private static void DrawLegenda(Graphics monitorGraphics, ScaledScreen scaledScreen, DesktopImage imageData, Form controlerForm)
        {
            // outine text
            // http://www.codeproject.com/Articles/42529/Outline-Text#singleoutline1
            //System.Drawing.Pen redPen = new System.Drawing.Pen(System.Drawing.Color.Red, 6);
            //System.Drawing.Pen yellowPen = new System.Drawing.Pen(System.Drawing.Color.Yellow, 2);
            //System.Drawing.SolidBrush brush = new System.Drawing.SolidBrush(System.Drawing.Color.Blue);

            monitorGraphics.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
            monitorGraphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;


            float textScale = scaledScreen.Scale;

            Rectangle legendaRect = GetLegendaRect(monitorGraphics, scaledScreen);


            // search for date taken
            DateTime dateTaken = DateTime.Now;

            //String tags = imageData.Image.Tag;


            foreach (PropertyItem propItem in imageData.Image.PropertyItems)
            {
                if (propItem.Id == PropertyTagExifDTOrig)
                {
                    string dateTakenString = dateRegex.Replace(Encoding.UTF8.GetString(propItem.Value), "-", 2);
                    dateTaken = DateTime.Parse(dateTakenString);
                }
            }

            // test for controler form
            if (controlerForm != null)
            {
                // update start
                controlerForm.Tag = imageData;
                controlerForm.Refresh();
                //UpdateDisplay(imageData);
                // draw each of the invisible controls
                foreach (Label label in controlerForm.Controls)
                {
                    // check "invisible" each element on the form
                    if (!label.Visible)
                    {
                        Image image  = label.Image;
                        int   x      = label.Left + controlerForm.Left;
                        int   y      = label.Top + controlerForm.Top;
                        int   width  = label.Width;
                        int   height = label.Height;

                        monitorGraphics.DrawImage(image, x, y, width, height);
                    }
                }
            }

            System.Drawing.StringFormat stringFormat = (StringFormat)StringFormat.GenericDefault.Clone();
            stringFormat.Trimming = StringTrimming.EllipsisPath;
            System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
            path.AddString(imageData.Filename,
                           FontFamily.GenericSansSerif,
                           (int)FontStyle.Regular,
                           (int)(20 * textScale),
                           new Rectangle(legendaRect.X, legendaRect.Y, legendaRect.Width, (int)(20 * textScale)),
                           stringFormat);
            path.AddString(imageData.DisplayFolder,
                           FontFamily.GenericSansSerif,
                           (int)FontStyle.Regular,
                           (int)(25 * textScale),
                           new Rectangle(legendaRect.X, legendaRect.Y + (int)(20 * textScale), legendaRect.Width, (int)(25 * textScale)),
                           stringFormat);
            path.AddString(string.Format("{0} x {1}", imageData.Image.Width, imageData.Image.Height),
                           FontFamily.GenericSansSerif,
                           (int)FontStyle.Regular,
                           (int)(16 * textScale),
                           new Rectangle(legendaRect.X, legendaRect.Y + (int)(50 * textScale), legendaRect.Width, (int)(16 * textScale)),
                           stringFormat);



            path.AddString(dateTaken.ToString("dd-MM-yyyy hh:mm"),
                           FontFamily.GenericSansSerif,
                           (int)FontStyle.Regular,
                           (int)(20 * textScale),
                           new Rectangle(legendaRect.X, legendaRect.Y + (int)(70 * textScale), legendaRect.Width, (int)(20 * textScale)),
                           stringFormat);


            //monitorGraphics.DrawPath(redPen, path);
            //monitorGraphics.DrawPath(yellowPen, path);
            //monitorGraphics.FillPath(brush, path);

            Color textColor = Color.FromArgb(255, 255, 255);
            Color glowColor = Color.FromArgb(0, 0, 0);
            //Color textColor = Color.FromArgb(0, 0, 0);
            //Color glowColor = Color.FromArgb(255, 255, 255);
            float glowScale = 1.0F;

            GlowText(monitorGraphics, path, textColor, glowColor, glowScale);
        }
예제 #6
0
        public static void CreateBackgroundImage(Dictionary <string, DesktopImage> images, Dictionary <string, Form> controlerForms)
        {
            var result = ScaledScreen.GetPerMonitorDPIAware();

            if (result != ScaledScreen.PROCESS_DPI_AWARENESS.PROCESS_PER_MONITOR_DPI_AWARE)
            {
                ScaledScreen.SetPerMonitorDPIAware();
            }

            ScaledScreen[] scaledScreens = ScaledScreen.AllScaledScreens;

            using (var virtualScreenBitmap = CreateScreenBitmap(scaledScreens))
            {
                using (var virtualScreenGraphic = Graphics.FromImage(virtualScreenBitmap))
                {
                    foreach (var scaledScreen in scaledScreens)
                    {
                        if (!images.ContainsKey(scaledScreen.DeviceName))
                        {
                            break;
                        }

                        var desktopImage = images[scaledScreen.DeviceName];

                        //var monitorDimensions = scaledScreen.Bounds;
                        var monitorBitmap   = new Bitmap(scaledScreen.UnscaledBounds.Width, scaledScreen.UnscaledBounds.Height);
                        var monitorGraphics = Graphics.FromImage(monitorBitmap);

                        // standard background
                        monitorGraphics.FillRectangle(SystemBrushes.Info, 0, 0, scaledScreen.UnscaledBounds.Width, scaledScreen.UnscaledBounds.Height);

                        // todo: extension add different centering zoom options: fill, fill center
                        if (desktopImage != null)
                        {
                            DrawImageFillCentered(ref monitorGraphics, desktopImage.Image, new Rectangle(0, 0, monitorBitmap.Width, monitorBitmap.Height));
                        }

                        // add text to image
                        Form controlerForm = null;
                        if (controlerForms.ContainsKey(scaledScreen.DeviceName))
                        {
                            controlerForm = controlerForms[scaledScreen.DeviceName];
                        }
                        DrawLegenda(monitorGraphics, scaledScreen, desktopImage, controlerForm);

                        // determine rectangle where the image will reside
                        Rectangle screenRectangle = new Rectangle(scaledScreen.UnscaledBounds.X - ScaledScreen.DesktopRectangle.X, scaledScreen.UnscaledBounds.Y - ScaledScreen.DesktopRectangle.Y, scaledScreen.UnscaledBounds.Width, scaledScreen.UnscaledBounds.Height);

                        // draw the image on the fill desktop image
                        virtualScreenGraphic.DrawImage(monitorBitmap, screenRectangle);

                        monitorGraphics.Dispose();
                        monitorBitmap.Dispose();
                    }

                    virtualScreenBitmap.Save(WallpaperPath + defaultBackgroundFileName, ImageFormat.Bmp);

                    virtualScreenGraphic.Dispose();
                    virtualScreenBitmap.Dispose();
                }
            }

            SystemParametersInfo(SPI_SETDESKWALLPAPER, 0u, WallpaperPath + defaultBackgroundFileName, SPIF_UPDATEINIFILE);
        }
예제 #7
0
        public static void CreateLogonScreenImage(DesktopImage desktopImage, string fullfilename)
        {
            var result = ScaledScreen.GetPerMonitorDPIAware();

            if (result != ScaledScreen.PROCESS_DPI_AWARENESS.PROCESS_PER_MONITOR_DPI_AWARE)
            {
                ScaledScreen.SetPerMonitorDPIAware();
            }

            ScaledScreen[] scaledScreens = ScaledScreen.AllScaledScreens;
            ScaledScreen   scaledScreen  = scaledScreens[0];

            using (var virtualScreenBitmap = new Bitmap(ScaledScreen.DesktopRectangle.Width, ScaledScreen.DesktopRectangle.Height))
            {
                using (var virtualScreenGraphic = Graphics.FromImage(virtualScreenBitmap))
                {
                    var monitorBitmap   = new Bitmap(scaledScreen.UnscaledBounds.Width, scaledScreen.UnscaledBounds.Height);
                    var monitorGraphics = Graphics.FromImage(monitorBitmap);

                    // standard background
                    monitorGraphics.FillRectangle(SystemBrushes.Info, 0, 0, scaledScreen.UnscaledBounds.Width, scaledScreen.UnscaledBounds.Height);

                    // todo: extension add different centering zoom options: fill, fill center
                    if (desktopImage != null)
                    {
                        DrawImageFillCentered(ref monitorGraphics, desktopImage.Image, new Rectangle(0, 0, monitorBitmap.Width, monitorBitmap.Height));
                    }

                    // add text to image
                    DrawLegenda(monitorGraphics, scaledScreen, desktopImage, null);

                    // determine rectangle where the image will reside
                    Rectangle screenRectangle = new Rectangle(scaledScreen.UnscaledBounds.X - ScaledScreen.DesktopRectangle.X, scaledScreen.UnscaledBounds.Y - ScaledScreen.DesktopRectangle.Y, scaledScreen.UnscaledBounds.Width, scaledScreen.UnscaledBounds.Height);

                    // draw the image on the fill desktop image
                    virtualScreenGraphic.DrawImage(monitorBitmap, screenRectangle);

                    monitorGraphics.Dispose();
                    monitorBitmap.Dispose();

                    virtualScreenBitmap.Save(fullfilename, ImageFormat.Png);

                    virtualScreenGraphic.Dispose();
                    virtualScreenBitmap.Dispose();

                    // https://docs.microsoft.com/en-us/uwp/api/Windows.System.UserProfile.LockScreen?view=winrt-18362
                    // https://github.com/Microsoft/Windows-universal-samples/tree/master/Samples/Personalization

                    // Microsoft.Win32.SessionSwitchReason.SessionLock // http://omegacoder.com/?p=516

                    // registry: Computer\HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Lock Screen
                    // https://winaero.com/blog/find-the-current-lock-screen-image-file-in-windows-10/

                    // https://winaero.com/blog/find-the-current-lock-screen-image-file-in-windows-10/

                    //await LockScreen.SetImageFileAsync(imageFile);
                    //System.UserProfile.LockScreen.SetImageFileAsync(File);
                }
            }

            //SystemParametersInfo(SPI_SETDESKWALLPAPER, 0u, WallpaperPath + defaultBackgroundFileName, SPIF_UPDATEINIFILE);
        }