protected override void SaveImageSettingsCore(CodedImage image)
        {
            base.SaveImageSettingsCore(image);

            image.AdditionalData[nameof(CropKind)] = CropKind.ToString();
            if (CropKind != ImageCropper.CropKind.None)
            {
                image.AdditionalData[nameof(CropRect)] = $"{CropRect.Left},{CropRect.Top},{CropRect.Width},{CropRect.Height}";
            }
        }
Example #2
0
        /// <summary>
        /// Creates cropped copy of source picture.
        /// </summary>
        /// <param name="sourceImage">Source picture instance.</param>
        /// <param name="cropRect">Rectange with cropping bounds.</param>
        /// <param name="cropKind">Cropping method.</param>
        /// <param name="destImage">Destionation <see cref="IndexedImage"/> object or null.</param>
        /// <returns>New or updated <see cref="IndexedImage"/> object with cropped picture.</returns>
        public static IndexedImage Crop(IndexedImage sourceImage, Rectangle cropRect, CropKind cropKind = CropKind.Rectangle, IndexedImage destImage = null)
        {
            Debug.Assert(destImage != sourceImage, "It's impossible to crop image into itself.");

            if (destImage == null)
            {
                destImage = new IndexedImage();
            }

            if (cropKind == CropKind.None)
            {
                destImage.Size = sourceImage.Size;
                sourceImage.Pixels.CopyTo(destImage.Pixels, 0);
            }
            else
            {
                destImage.Size = new Size(cropRect.Width, cropRect.Height);
                switch (cropKind)
                {
                case CropKind.Arc:
                    CropArc(sourceImage.Pixels, destImage.Pixels, sourceImage.Size, cropRect);
                    break;

                case CropKind.Rectangle:
                default:
                    CropRect(sourceImage.Pixels, destImage.Pixels, sourceImage.Size, cropRect);
                    break;
                }
            }

            return(destImage);
        }