Beispiel #1
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);
        }
Beispiel #2
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);
        }
Beispiel #3
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);
        }