Пример #1
0
 private void ImageCropper_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.KeyCode == Keys.R)
     {
         _cropperPictureBox.Image = (Bitmap)ImageCropperHelper.RotateImage(_cropperPictureBox.Image);
         GC.Collect();
     }
     if (e.KeyCode == Keys.S)
     {
         var image    = _cropperPictureBox.Image;
         var diff     = _cropperPictureBox.Image.Width - _cropperPictureBox.Image.Height;
         var location =
             diff > 0
                 ? new Point(_selectorRectangle.X, _selectorRectangle.Y - diff / 2)
                 : new Point(_selectorRectangle.X + diff / 2, _selectorRectangle.Y);
         var area = new Rectangle(location, _selectorRectangle.Size);
         try
         {
             using (var croppedImage = ((Bitmap)image).Clone(area, image.PixelFormat))
             {
                 var path = Path.Combine(_outputDirectory, "1.png");
                 croppedImage?.Save(path);
             }
         }
         catch { }
         GC.Collect();
     }
 }
Пример #2
0
        public ImageCropper(string originalImagePath, string outputDirectory, List <string> imagesToCrop)
        {
            InitializeComponent();

            _imagesToCrop    = imagesToCrop;
            _outputDirectory = outputDirectory;

            this.Width  = _frameWidth + 16;
            this.Height = _frameWidth + 39;

            _cropperPictureBox.Width  = _frameWidth;
            _cropperPictureBox.Height = _frameWidth;

            foreach (var imageToCrop in imagesToCrop)
            {
            }

            OriginalImage = originalImagePath;

            var image = ImageCropperHelper.GetScaledPicture(OriginalImage, _frameWidth, _frameWidth);

            _cropperPictureBox.Image = image;
            Refresh();
        }