コード例 #1
0
 private void RefreshCropImage()
 {
     if (_clp != null)
     {
         Rect rc = _clp.ClippingRectangle;
         tblkClippingRectangle.Text = string.Format(
             "Clipping Rectangle: ({0:N1}, {1:N1}, {2:N1}, {3:N1})",
             rc.Left,
             rc.Top,
             rc.Right,
             rc.Bottom);
         imgCrop.Source = _clp.BpsCrop();
     }
 }
コード例 #2
0
        private void AddCropToElement(FrameworkElement fel)
        {
            if (_felCur != null)
            {
                RemoveCropFromCur();
            }
            Rect rcInterior = new Rect(0, 0, 0, 0);

            rcInterior = new Rect(
                X - (AnchoReal / 2),
                Y - (AltoReal / 2),
                AnchoReal,
                AltoReal);

            AdornerLayer aly = AdornerLayer.GetAdornerLayer(fel);

            _clp = new CroppingAdorner(fel, rcInterior);
            aly.Add(_clp);
            imgCrop.Source    = _clp.BpsCrop();
            _clp.CropChanged += CropChanged;
            _felCur           = fel;
            //if (rbRed.IsChecked != true)
            //{
            //    SetClipColorGrey();
            //}
        }
コード例 #3
0
 /// <summary>Crops image bounded by rectangle of cropper</summary>
 /// <param name="image">image that will be cropped</param>
 /// <param name="cropper">object responsible for cropping</param>
 public static BitmapSource CropImage(BitmapSource image, CroppingAdorner cropper)
 {
     if (cropper != null)
     {
         return(cropper.BpsCrop(image));
     }
     else
     {
         return(null);
     }
 }
コード例 #4
0
        public CropWindow(string fileName)
        {
            InitializeComponent();

            _fileName = fileName;

            using (var stream = File.OpenRead(fileName))
            {
                var decoder = BitmapDecoder.Create(stream, BitmapCreateOptions.None, BitmapCacheOption.OnLoad);

                Image.Source = decoder.Frames[0];
            }

            Loaded += (s, e) =>
            {
                var rcInterior = new Rect(
                    Image.ActualWidth * 0.2,
                    Image.ActualHeight * 0.2,
                    Image.ActualWidth * 0.6,
                    Image.ActualHeight * 0.6);

                var layer = AdornerLayer.GetAdornerLayer(Image);

                var croppingAdorner = new CroppingAdorner(Image, rcInterior);

                layer.Add(croppingAdorner);

                void RefreshCropImage()
                {
                    _croppedImage = croppingAdorner.BpsCrop(Image.Source as BitmapSource);

                    SizeLabel.Content = _croppedImage != null
                        ? $"{(int) _croppedImage.Width} x {(int) _croppedImage.Height}"
                        : "";
                }

                RefreshCropImage();

                croppingAdorner.CropChanged += (sender, args) => RefreshCropImage();

                croppingAdorner.Checked += Save;

                var clr = Colors.Black;
                clr.A = 110;
                croppingAdorner.Fill = new SolidColorBrush(clr);
            };
        }
コード例 #5
0
        private void AddCropToElement(FrameworkElement fel)
        {
            if (_felCur != null)
            {
                RemoveCropFromCur();
            }
            Rect rcInterior = new Rect(
                fel.ActualWidth * 0.2,
                fel.ActualHeight * 0.2,
                fel.ActualWidth * 0.6,
                fel.ActualHeight * 0.6);
            AdornerLayer aly = AdornerLayer.GetAdornerLayer(fel);

            _clp = new CroppingAdorner(fel, rcInterior);
            aly.Add(_clp);
            imgCrop.Source    = _clp.BpsCrop();
            _clp.CropChanged += CropChanged;
            _felCur           = fel;
            if (rbRed.IsChecked != true)
            {
                SetClipColorGrey();
            }
        }