private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            this.RemoveSystemMenuItems(Win32.SystemMenuItems.All); //去除窗口指定的系统菜单

            _oldWidth               = Math.Round(_imageControl.Width, 2);
            _oldHeight              = Math.Round(_imageControl.Height, 2);
            _oldTranslateX          = Math.Round(_translateTransform.X, 2);
            _oldTranslateY          = Math.Round(_translateTransform.Y, 2);
            _oldInitMaxImgSize      = Math.Round(_userConfig.ImageSetting.InitMaxImgSize);
            _oldAnimatedGif         = (AnimatedImage.AnimatedGif)_imageControl.Content;
            _oldPath                = _userConfig.ImageSetting.MainMenuInfo.Path;
            _oldGlobelAddShortcut   = (Shortcut)_userConfig.ShortcutSetting.GlobelAddShortcut.Clone();
            _oldGlobelPasteShortcut = (Shortcut)_userConfig.ShortcutSetting.GlobelPasteShortcut.Clone();
            _oldAutoRun             = _userConfig.AppSetting.AutoRun;

            HeightTbx.Text      = _oldHeight.ToString(CultureInfo.InvariantCulture);
            WidthTbx.Text       = _oldWidth.ToString(CultureInfo.InvariantCulture);
            LocationXTbx.Text   = _oldTranslateX.ToString(CultureInfo.InvariantCulture);
            LocationYTbx.Text   = _oldTranslateY.ToString(CultureInfo.InvariantCulture);
            MaxSizeTbx.Text     = _oldInitMaxImgSize.ToString(CultureInfo.InvariantCulture);
            AutoRunCk.IsChecked = _oldAutoRun;

            CtrlCbx1.IsChecked  = _oldGlobelAddShortcut.IsCtrl;
            AltCbx1.IsChecked   = _oldGlobelAddShortcut.IsAlt;
            ShiftCbx1.IsChecked = _oldGlobelAddShortcut.IsShift;
            KeyTbx1.Text        = _oldGlobelAddShortcut.Key.ToString();

            CtrlCbx2.IsChecked  = _oldGlobelPasteShortcut.IsCtrl;
            AltCbx2.IsChecked   = _oldGlobelPasteShortcut.IsAlt;
            ShiftCbx2.IsChecked = _oldGlobelPasteShortcut.IsShift;
            KeyTbx2.Text        = _oldGlobelPasteShortcut.Key.ToString();

            _canTextChange = true;
        }
Exemple #2
0
        private void WindowClosing(object sender, CancelEventArgs e)
        {
            var isChanged = CropRect.Width >= 1 && CropRect.Height >= 1 &&
                            (CropRect.Width < _imageViewWidth || CropRect.Height < _imageViewHeight);

            if (_isSave && isChanged)
            {
                var left       = (int)(CropRect.Margin.Left / _imageViewWidth * _pixelWidth);
                var top        = (int)(CropRect.Margin.Top / _imageViewHeight * _pixelHeight);
                var width      = (int)(CropRect.Width / _imageViewWidth * _pixelWidth);
                var height     = (int)(CropRect.Height / _imageViewHeight * _pixelHeight);
                var realWidth  = (int)(CropRect.Width / _imageViewWidth * _imageWidth);
                var realHeight = (int)(CropRect.Height / _imageViewHeight * _imageHeight);
                if (width == 0 || height == 0 || realWidth == 0 || realHeight == 0)
                {
                    return;
                }
                var croppedBox = new Int32Rect(left, top, width, height);

                BitmapSource bitmapSource;
                if (_animatedGif.Animatable)
                {
                    var bitmapFrames = _animatedGif.BitmapFrames;
                    var stream       = new MemoryStream();
                    using (var encoder = new GifEncoder(stream, realWidth, realHeight, _animatedGif.RepeatCount))
                    {
                        var delays = _animatedGif.Delays;
                        for (var i = 0; i < bitmapFrames.Count; i++)
                        {
                            using (var bitmap = new CroppedBitmap(bitmapFrames[i], croppedBox).GetResizeBitmap(realWidth, realHeight).GetBitmap())
                            {
                                encoder.AppendFrame(bitmap, (int)delays[i].TotalMilliseconds);
                            }
                        }
                    }
                    stream.Position = 0;
                    var bitmapImage = new BitmapImage();
                    bitmapImage.BeginInit();
                    bitmapImage.StreamSource = stream;
                    bitmapImage.EndInit();
                    bitmapSource = bitmapImage;
                }
                else
                {
                    bitmapSource = _animatedGif.Source as BitmapSource;
                    if (bitmapSource == null)
                    {
                        return;
                    }
                    bitmapSource = new CroppedBitmap(bitmapSource, croppedBox).GetResizeBitmap(realWidth, realHeight).GetBitmapImage();
                }

                NewAnimatedGif = new AnimatedImage.AnimatedGif()
                {
                    Source = bitmapSource, Stretch = Stretch.Fill
                };
            }
        }
 private void WindowClosing(object sender, System.ComponentModel.CancelEventArgs e)
 {
     if (_isSave)
     {
         NewAnimatedGif = new AnimatedImage.AnimatedGif()
         {
             Source = GetAnimatedGif(), Stretch = Stretch.Fill
         };
     }
     SaveCurrentState();
 }
        public GifDrawingWindow(AnimatedImage.AnimatedGif animatedGif, int width, int height)
        {
            InitializeComponent();
            var screenHeight = SystemParameters.VirtualScreenHeight;
            var screenWidth  = SystemParameters.VirtualScreenWidth;

            _animatedGif    = animatedGif;
            GifImage.Source = _animatedGif.Source;
            _imageWidth     = width;
            _imageHeight    = height;

            var winHeight = _imageHeight + 140.0;
            var winWidth  = _imageWidth + 40.0;

            if (winHeight < 400)
            {
                winHeight = 400;
            }
            else if (winHeight > screenHeight)
            {
                winHeight = screenHeight;
            }
            if (winWidth < 400)
            {
                winWidth = 400;
            }
            else if (winWidth > screenWidth)
            {
                winWidth = screenWidth;
            }
            Height = winHeight;
            Width  = winWidth;
            ImageVisulGrid.Height = _imageHeight;
            ImageVisulGrid.Width  = _imageWidth;

            _linePoints     = new List <Point>();
            _isSave         = false;
            _drawingChanged = false;
            _selectedButton = PenToolBtn;
            _drawingTool    = DrawingTool.PenTool;
            _pickedColor    = Color.Transparent;
            _drawingManager = new DrawingManager(TargetImage, new Bitmap(_imageWidth, _imageHeight, PixelFormat.Format32bppArgb))
            {
                RedoButtuon = RedoButton,
                UndoButton  = UndoButton,
            };

            _drawingConfigution = new DrawingConfig();
            _drawingConfigution.LoadConfigFromXml(ConfigurationManager.AppSettings[ConfigPathKey]);
        }
Exemple #5
0
        public GifCropWindow(AnimatedImage.AnimatedGif animatedGif, int width, int height)
        {
            InitializeComponent();
            var screenHeight = (int)SystemParameters.VirtualScreenHeight;
            var screenWidth  = (int)SystemParameters.VirtualScreenWidth;

            _animatedGif     = animatedGif;
            _imageViewWidth  = _imageWidth = width;
            _imageViewHeight = _imageHeight = height;
            _pixelWidth      = _animatedGif.BitmapFrames.First().PixelWidth;
            _pixelHeight     = _animatedGif.BitmapFrames.First().PixelHeight;

            if (_imageViewWidth > screenWidth - 40)
            {
                _imageViewHeight = (screenWidth - 40) * _imageViewHeight / _imageViewWidth;
                _imageViewWidth  = screenWidth - 40;
            }

            if (_imageViewHeight > screenHeight - 125)
            {
                _imageViewWidth  = (screenHeight - 125) * _imageViewWidth / _imageViewHeight;
                _imageViewHeight = screenHeight - 125;
            }
            var winHeight = _imageViewHeight + 125.0;
            var winWidth  = _imageViewWidth + 40.0;

            if (winHeight < 300)
            {
                winHeight = 300;
            }
            if (winWidth < 300)
            {
                winWidth = 300;
            }
            Height                = winHeight;
            Width                 = winWidth;
            TargetImage.Source    = _animatedGif.Source;
            ImageVisulGrid.Height = _imageViewHeight;
            ImageVisulGrid.Width  = _imageViewWidth;


            _isSave         = false;
            _isMousePressed = false;
        }