private void OnRegionSelected(RegionSelectedEventArgs e)
 {
     if (RegionSelected != null)
     {
         RegionSelected(this, e);
     }
 }
        private void Image_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            image.ReleaseMouseCapture();
            // Get actual rectangle
            if (selectBox.Visibility != Visibility.Visible)
            {
                return;
            }

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

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

            BitmapSource bmpSource = image.Source as BitmapSource;

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

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

            if ((int)newWidth == 0 || (int)newHeight == 0)
            {
                // Doesn't make sense, further code can't handle this.
                return;
            }

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

            System.Drawing.Bitmap src = System.Drawing.Image.FromFile(_sourceFile) as System.Drawing.Bitmap;
            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);
            }

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

            OnRegionSelected(ev);

            selectBox.Visibility = Visibility.Hidden;
        }
示例#3
0
        private void fieldSelected(object sender, RegionSelectedEventArgs e)
        {
            string tempFilePath = System.IO.Path.GetTempFileName();

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

            string outputDir = getOutputDir();

            UserTask task = new UserTask(tempFilePath);

            task.TaskStatus       = "Uploading";
            task.SourceIsTempFile = true;
            task.IsFieldLevel     = true;

            // TODO: correct output name
            task.OutputFilePath = System.IO.Path.Combine(
                outputDir,
                "field-level" + System.IO.Path.GetRandomFileName() + ".xml");

            task.SourceImage = e.CroppedImage;

            _userTasks.Add(task);
            _fieldLevelTasks.Add(task);



            // Select mode: text, barcode, checkmark
            if (flModeText.IsChecked == true)
            {
                TextFieldProcessingSettings settings = new TextFieldProcessingSettings();
                restClientAsync.ProcessTextFieldAsync(tempFilePath, settings, task);
            }
            else if (flModeBarcode.IsChecked == true)
            {
                BarcodeFieldProcessingSettings settings = new BarcodeFieldProcessingSettings();
                restClientAsync.ProcessBarcodeFieldAsync(tempFilePath, settings, task);
            }
            else
            {
                CheckmarkFieldProcessingSettings settings = new CheckmarkFieldProcessingSettings();
                string userSettings = Properties.Settings.Default.CheckmarkOptions;
                if (!String.IsNullOrEmpty(userSettings))
                {
                    settings.Params = userSettings;
                }

                restClientAsync.ProcessCheckmarkFieldAsync(tempFilePath, settings, task);
            }

            // temp file will be deleted in ProcessingCompleted callback
        }
示例#4
0
        private void fieldSelected(object sender, RegionSelectedEventArgs e)
        {
            string tempFilePath = System.IO.Path.GetTempFileName();
            e.CroppedImage.Save(tempFilePath, System.Drawing.Imaging.ImageFormat.Tiff);

            string outputDir = getOutputDir();

            UserTask task = new UserTask(tempFilePath);
            task.TaskStatus = "Uploading";
            task.SourceIsTempFile = true;
            task.IsFieldLevel = true;

            // TODO: correct output name
            task.OutputFilePath = System.IO.Path.Combine(
                outputDir,
                "field-level" + System.IO.Path.GetRandomFileName() + ".xml");

            task.SourceImage = e.CroppedImage;

            _userTasks.Add(task);
            _fieldLevelTasks.Add(task);

            

            // Select mode: text, barcode, checkmark
            if (flModeText.IsChecked == true)
            {
                TextFieldProcessingSettings settings = new TextFieldProcessingSettings();
                restClientAsync.ProcessTextFieldAsync(tempFilePath, settings, task);
            }
            else if (flModeBarcode.IsChecked == true)
            {
                BarcodeFieldProcessingSettings settings = new BarcodeFieldProcessingSettings();
                restClientAsync.ProcessBarcodeFieldAsync(tempFilePath, settings, task);
            }
            else
            {
                CheckmarkFieldProcessingSettings settings = new CheckmarkFieldProcessingSettings();
                string userSettings = Properties.Settings.Default.CheckmarkOptions;
                if (!String.IsNullOrEmpty(userSettings))
                    settings.Params = userSettings;

                restClientAsync.ProcessCheckmarkFieldAsync(tempFilePath, settings, task);
            }

            // temp file will be deleted in ProcessingCompleted callback
        }
        private void Image_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
        {
            image.ReleaseMouseCapture();
           // Get actual rectangle
            if( selectBox.Visibility != Visibility.Visible)
                return;

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

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

            BitmapSource bmpSource = image.Source as BitmapSource;

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

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

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


            System.Drawing.Bitmap src = System.Drawing.Image.FromFile(_sourceFile) as System.Drawing.Bitmap;
            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);
            }

           


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

            selectBox.Visibility = Visibility.Hidden;
        }
 private void OnRegionSelected( RegionSelectedEventArgs e )
 {
     if (RegionSelected != null)
         RegionSelected(this, e);
 }