public override void CropImage(CropInput cropInput)
        {
            var input = cropInput as RectangleCropInput;

            if (input.DecreasePercentage >= 100)
            {
                throw new ArgumentException("Value of percentage to decrease image must be less than 100%");
            }

            float     fraction      = input.DecreasePercentage / 100.0f;
            Rectangle cropRectangle = new Rectangle(
                (int)(_sourceImage.Width * (fraction / 2)),
                (int)(_sourceImage.Height * (fraction / 2)),
                (int)(_sourceImage.Width * 3 * fraction),
                (int)(_sourceImage.Height * 3 * fraction));

            _targetImage = new Bitmap(cropRectangle.Width, cropRectangle.Height);

            using (Graphics graphics = Graphics.FromImage(_targetImage))
            {
                graphics.DrawImage(_sourceImage, new Rectangle(0, 0, _targetImage.Width, _targetImage.Height),
                                   cropRectangle,
                                   GraphicsUnit.Pixel);
            }
        }
        public override void CropImage(CropInput cropInput)
        {
            var input = cropInput as EllipseCropInput;

            if (_sourceImage.Height <= input.HeightOffset || _sourceImage.Width <= input.WidthOffset)
            {
                throw new ArgumentException("Offset cannot be greater than width or height");
            }

            _targetImage = new Bitmap(_sourceImage.Width, _sourceImage.Height);
            var       graphicsPath  = new GraphicsPath();
            Rectangle cropRectangle = new Rectangle(input.WidthOffset / 2, input.HeightOffset / 2,
                                                    _sourceImage.Width - input.WidthOffset, _sourceImage.Height - input.HeightOffset);

            graphicsPath.AddEllipse(cropRectangle);

            using (Graphics graphics = Graphics.FromImage(_targetImage))
            {
                graphics.SetClip(graphicsPath);
                graphics.Clear(Color.White);
                graphics.DrawImage(_sourceImage, new Rectangle(0, 0, _sourceImage.Width, _sourceImage.Height),
                                   0, 0, _sourceImage.Width, _sourceImage.Height, GraphicsUnit.Pixel);
            }

            _targetImage.MakeTransparent(Color.White);
        }
 public ActionResult OCrop(CropInput cropDisplay)
 {
     return(View(cropDisplay));
 }
Beispiel #4
0
 public abstract void CropImage(CropInput cropInput);