Exemple #1
0
        /// <summary>
        /// Composes a set of new images by applying the specified overlay to each image and appending it to the list.
        /// </summary>
        /// <param name="imageList">The base images.</param>
        /// <param name="overlay">The overlay image.</param>
        /// <param name="keySuffix">A suffix to be appended to the key of each composed image.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="imageList" /> is null.
        /// <para>or</para>
        /// <paramref name="overlay" /> is null.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// <paramref name="keySuffix" /> is null or empty.
        /// </exception>
        public static void Append(ImageList imageList, ImageOverlay overlay, string keySuffix)
        {
            if (imageList == null)
            {
                throw new ArgumentNullException(nameof(imageList));
            }

            if (overlay == null)
            {
                throw new ArgumentNullException(nameof(overlay));
            }

            if (string.IsNullOrEmpty(keySuffix))
            {
                throw new ArgumentException("Key suffix cannot be null or empty.", nameof(keySuffix));
            }

            using (Image overlayImage = overlay.Image.Crop(overlay.CropArea))
            {
                foreach (string key in imageList.Images.Keys)
                {
                    Image  image  = imageList.Images[key];
                    Point  offset = GetOverlayOffset(image, overlay);
                    string newKey = key + keySuffix;
                    imageList.Images.Add(newKey, Compose(image, overlayImage, offset));
                }
            }
        }
Exemple #2
0
 private static Point GetOverlayOffset(Image original, ImageOverlay overlay)
 {
     return(new Point
     {
         X = GetHorizontalOffset(original.Width, overlay.CropArea.Width, overlay.HorizontalAlignment),
         Y = GetVerticalOffset(original.Height, overlay.CropArea.Height, overlay.VerticalAlignment)
     });
 }
Exemple #3
0
        /// <summary>
        /// Composes a new <see cref="Image" /> by applying the specified overlay to the base image.
        /// </summary>
        /// <param name="image">The base image.</param>
        /// <param name="overlay">The overlay image.</param>
        /// <returns>A new overlaid <see cref="Image" />.</returns>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="image" /> is null.
        /// <para>or</para>
        /// <paramref name="overlay" /> is null.
        /// </exception>
        public static Image Create(Image image, ImageOverlay overlay)
        {
            if (image == null)
            {
                throw new ArgumentNullException(nameof(image));
            }

            if (overlay == null)
            {
                throw new ArgumentNullException(nameof(overlay));
            }

            using (Image overlayImage = overlay.Image.Crop(overlay.CropArea))
            {
                Point offset = GetOverlayOffset(image, overlay);
                return(Compose(image, overlayImage, offset));
            }
        }