Ejemplo n.º 1
0
        public ImagePanel()
        {
            InitializeComponent();

            Resources.MergedDictionaries.Clear();

            buttonMeta.Click += (sender, e) =>
                                textMeta.Visibility = textMeta.Visibility == Visibility.Collapsed
                    ? Visibility.Visible
                    : Visibility.Collapsed;

            var scale = DpiHelper.GetCurrentScaleFactor();

            backgroundBrush.Viewport = new Rect(new Size(
                                                    backgroundBrush.ImageSource.Width / scale.Horizontal,
                                                    backgroundBrush.ImageSource.Height / scale.Vertical));

            SizeChanged += ImagePanel_SizeChanged;

            viewPanel.PreviewMouseWheel   += ViewPanel_PreviewMouseWheel;
            viewPanel.MouseLeftButtonDown += ViewPanel_MouseLeftButtonDown;
            viewPanel.MouseMove           += ViewPanel_MouseMove;

            viewPanel.ManipulationInertiaStarting += ViewPanel_ManipulationInertiaStarting;
            viewPanel.ManipulationStarting        += ViewPanel_ManipulationStarting;
            viewPanel.ManipulationDelta           += ViewPanel_ManipulationDelta;
        }
Ejemplo n.º 2
0
        private void WindowDragMoving(object sender, MouseEventArgs e)
        {
            if (e.LeftButton != MouseButtonState.Pressed)
            {
                return;
            }
            if (!_restoreForDragMove)
            {
                return;
            }
            _restoreForDragMove = false;

            var scale = DpiHelper.GetCurrentScaleFactor();
            var point = PointToScreen(e.MouseDevice.GetPosition(this));

            point.X /= scale.Horizontal;
            point.Y /= scale.Vertical;

            var monitor     = WindowHelper.GetCurrentWindowRect();
            var precentLeft = (point.X - monitor.Left) / monitor.Width;
            var precentTop  = (point.Y - monitor.Top) / monitor.Height;

            Left = point.X - RestoreBounds.Width * precentLeft;
            Top  = point.Y - RestoreBounds.Height * precentTop;

            WindowState = WindowState.Normal;

            if (e.LeftButton == MouseButtonState.Pressed)
            {
                DragMove();
            }
        }
Ejemplo n.º 3
0
        public static Rect GetCurrentWindowRect()
        {
            var screen = Screen.FromPoint(Cursor.Position).WorkingArea;
            var scale  = DpiHelper.GetCurrentScaleFactor();

            return(new Rect(
                       new Point(screen.X / scale.Horizontal, screen.Y / scale.Vertical),
                       new Size(screen.Width / scale.Horizontal, screen.Height / scale.Vertical)));
        }
Ejemplo n.º 4
0
        private Icon GetTrayIconByDPI()
        {
            var scale = DpiHelper.GetCurrentScaleFactor().Vertical;

            if (App.IsWin10)
            {
                return(scale > 1 ? Resources.app_white : Resources.app_white_16);
            }
            return(scale > 1 ? Resources.app : Resources.app_16);
        }
Ejemplo n.º 5
0
        private Icon GetTrayIconByDPI()
        {
            var isWin10 = Environment.OSVersion.Version >= new Version(10, 0);
            var scale   = DpiHelper.GetCurrentScaleFactor().Vertical;

            if (isWin10)
            {
                return(scale > 1 ? Resources.app_white : Resources.app_white_16);
            }
            return(scale > 1 ? Resources.app : Resources.app_16);
        }
Ejemplo n.º 6
0
        public override Task <BitmapSource> GetRenderedFrame(int index)
        {
            var fullSize = Meta.GetSize();

            return(new Task <BitmapSource>(() =>
            {
                var settings = new MagickReadSettings
                {
                    BackgroundColor = MagickColors.None,
                    Defines = new DngReadDefines
                    {
                        OutputColor = DngOutputColor.SRGB,
                        UseCameraWhitebalance = true,
                        DisableAutoBrightness = false
                    }
                };

                try
                {
                    using (var mi = new MagickImage(Path.LocalPath, settings))
                    {
                        var profile = mi.GetColorProfile();
                        if (mi.ColorSpace == ColorSpace.RGB || mi.ColorSpace == ColorSpace.sRGB ||
                            mi.ColorSpace == ColorSpace.scRGB)
                        {
                            if (profile?.Description != null && !profile.Description.Contains("sRGB"))
                            {
                                mi.SetProfile(ColorProfile.SRGB);
                            }
                        }

                        mi.AutoOrient();

                        if (mi.Width != (int)fullSize.Width || mi.Height != (int)fullSize.Height)
                        {
                            mi.Resize((int)fullSize.Width, (int)fullSize.Height);
                        }

                        mi.Density = new Density(DpiHelper.DefaultDpi * DpiHelper.GetCurrentScaleFactor().Horizontal,
                                                 DpiHelper.DefaultDpi * DpiHelper.GetCurrentScaleFactor().Vertical);

                        var img = mi.ToBitmapSourceWithDensity();

                        img.Freeze();
                        return img;
                    }
                }
                catch (Exception e)
                {
                    ProcessHelper.WriteLog(e.ToString());
                    return null;
                }
            }));
        }
Ejemplo n.º 7
0
        private Icon GetTrayIconByDPI()
        {
            var scale = DpiHelper.GetCurrentScaleFactor().Vertical;

            if (!App.IsWin10)
            {
                return(scale > 1 ? Resources.app : Resources.app_16);
            }

            return(OSThemeHelper.SystemUsesDarkTheme()
                ? (scale > 1 ? Resources.app_white : Resources.app_white_16)
                : (scale > 1 ? Resources.app_black : Resources.app_black_16));
        }
Ejemplo n.º 8
0
        private Rect ResizeAndCentreNewWindow(Size size)
        {
            var desktopRect = WindowHelper.GetCurrentDesktopRectInPixel();
            var scale       = DpiHelper.GetCurrentScaleFactor();
            var pxSize      = new Size(scale.Horizontal * size.Width, scale.Vertical * size.Height);

            var pxLocation = new Point(
                desktopRect.X + (desktopRect.Width - pxSize.Width) / 2,
                desktopRect.Y + (desktopRect.Height - pxSize.Height) / 2);

            // return absolute location and relative size
            return(new Rect(pxLocation, size));
        }
Ejemplo n.º 9
0
        public GifAnimationProvider(string path, MetaProvider meta) : base(path, meta)
        {
            _fileHandle = (Bitmap)Image.FromFile(path);

            _fileHandle.SetResolution(DpiHelper.DefaultDpi * DpiHelper.GetCurrentScaleFactor().Horizontal,
                                      DpiHelper.DefaultDpi * DpiHelper.GetCurrentScaleFactor().Vertical);

            Animator = new Int32AnimationUsingKeyFrames {
                RepeatBehavior = RepeatBehavior.Forever
            };
            Animator.KeyFrames.Add(new DiscreteInt32KeyFrame(0, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(0))));
            Animator.KeyFrames.Add(new DiscreteInt32KeyFrame(1, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(10))));
            Animator.KeyFrames.Add(new DiscreteInt32KeyFrame(2, KeyTime.FromTimeSpan(TimeSpan.FromMilliseconds(20))));
        }
Ejemplo n.º 10
0
        public static void DpiHack(BitmapSource img)
        {
            // a dirty hack... but is the fastest

            var newDpiX = (double) DpiHelper.DefaultDpi * DpiHelper.GetCurrentScaleFactor().Horizontal;
            var newDpiY = (double) DpiHelper.DefaultDpi * DpiHelper.GetCurrentScaleFactor().Vertical;

            var dpiX = img.GetType().GetField("_dpiX",
                BindingFlags.NonPublic | BindingFlags.Instance);
            var dpiY = img.GetType().GetField("_dpiY",
                BindingFlags.NonPublic | BindingFlags.Instance);
            dpiX?.SetValue(img, newDpiX);
            dpiY?.SetValue(img, newDpiY);
        }
Ejemplo n.º 11
0
        public GlassLayer()
        {
            InitializeComponent();

            var scale = DpiHelper.GetCurrentScaleFactor();

            noiseBrush.Viewport = new Rect(new Size(
                                               noiseBrush.ImageSource.Width / scale.Horizontal,
                                               noiseBrush.ImageSource.Height / scale.Vertical));

            LayoutUpdated += (sender, e) =>
            {
                BindingOperations.GetBindingExpressionBase(brush, TileBrush.ViewboxProperty)?.UpdateTarget();
            };
        }
Ejemplo n.º 12
0
        public ImagePanel()
        {
            InitializeComponent();

            var scale = DpiHelper.GetCurrentScaleFactor();

            backgroundBrush.Viewport = new Rect(new Size(
                                                    backgroundBrush.ImageSource.Width / scale.Horizontal,
                                                    backgroundBrush.ImageSource.Height / scale.Vertical));

            SizeChanged += ImagePanel_SizeChanged;

            viewPanel.PreviewMouseWheel   += ViewPanel_PreviewMouseWheel;
            viewPanel.MouseLeftButtonDown += ViewPanel_MouseLeftButtonDown;
            viewPanel.MouseMove           += ViewPanel_MouseMove;

            viewPanel.ManipulationInertiaStarting += ViewPanel_ManipulationInertiaStarting;
            viewPanel.ManipulationStarting        += ViewPanel_ManipulationStarting;
            viewPanel.ManipulationDelta           += ViewPanel_ManipulationDelta;
        }
Ejemplo n.º 13
0
        public override Task <BitmapSource> GetRenderedFrame(int index)
        {
            var fullSize = Meta.GetSize();

            return(new Task <BitmapSource>(() =>
            {
                try
                {
                    using (var mi = new MagickImage(Path))
                    {
                        var profile = mi.GetColorProfile();
                        if (profile?.Description != null && !profile.Description.Contains("sRGB"))
                        {
                            mi.SetProfile(ColorProfile.SRGB);
                        }

                        mi.AutoOrient();

                        if (mi.Width != (int)fullSize.Width || mi.Height != (int)fullSize.Height)
                        {
                            mi.Resize((int)fullSize.Width, (int)fullSize.Height);
                        }

                        mi.Density = new Density(DpiHelper.DefaultDpi * DpiHelper.GetCurrentScaleFactor().Horizontal,
                                                 DpiHelper.DefaultDpi * DpiHelper.GetCurrentScaleFactor().Vertical);

                        var img = mi.ToBitmapSource(BitmapDensity.Use);

                        img.Freeze();
                        return img;
                    }
                }
                catch (Exception e)
                {
                    ProcessHelper.WriteLog(e.ToString());
                    return null;
                }
            }));
        }