private async void FieldSelected(object sender, RegionSelectedEventArgs e)
        {
            var tempFilePath = Path.GetTempFileName();

            e.CroppedImage.Save(tempFilePath, System.Drawing.Imaging.ImageFormat.Tiff);

            await AddFileTaskAsync(tempFilePath, e.CroppedImage);
        }
Exemplo n.º 2
0
        private void Image_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            image.ReleaseMouseCapture();

            if (selectBox.Visibility != Visibility.Visible)
            {
                return;
            }

            var imageOffset = VisualTreeHelper.GetOffset(image);
            var visualLeft  = Canvas.GetLeft(selectBox);
            var visualTop   = Canvas.GetTop(selectBox);

            var width  = selectBox.Width;
            var height = selectBox.Height;

            var bmpSource = (BitmapSource)image.Source;

            var scaleX = bmpSource.PixelWidth / image.ActualWidth;
            var scaleY = bmpSource.PixelHeight / image.ActualHeight;

            var newWidth  = width * scaleX;
            var newHeight = height * scaleY;

            if ((int)newWidth == 0 || (int)newHeight == 0)
            {
                return;
            }

            var newX = (visualLeft - imageOffset.X) * scaleX;
            var newY = (visualTop - imageOffset.Y) * scaleY;

            var src    = (System.Drawing.Bitmap)System.Drawing.Image.FromFile(_sourceFile);
            var target = new System.Drawing.Bitmap((int)newWidth, (int)newHeight);

            target.SetResolution(src.HorizontalResolution, src.VerticalResolution);

            using (var g = System.Drawing.Graphics.FromImage(target))
            {
                var rect = new System.Drawing.Rectangle((int)newX, (int)newY, (int)newWidth, (int)newHeight);
                g.DrawImage(
                    src,
                    new System.Drawing.Rectangle(0, 0, target.Width, target.Height),
                    rect,
                    System.Drawing.GraphicsUnit.Pixel);
            }

            var ev = new RegionSelectedEventArgs(new Rect(newX, newY, newWidth, newHeight), target);

            OnRegionSelected(ev);

            selectBox.Visibility = Visibility.Hidden;
        }
Exemplo n.º 3
0
 private void OnRegionSelected(RegionSelectedEventArgs e)
 {
     RegionSelected?.Invoke(this, e);
 }