예제 #1
0
        /// <summary>
        /// Parses the input string to return the correct <see cref="ISupportedImageFormat"/>.
        /// </summary>
        /// <param name="identifier">
        /// The identifier.
        /// </param>
        /// <returns>
        /// The <see cref="ISupportedImageFormat"/>.
        /// </returns>
        private ISupportedImageFormat ParseFormat(string identifier)
        {
            identifier = identifier.ToLowerInvariant();
            string finalIdentifier = identifier.Equals("png8") ? "png" : identifier;
            ISupportedImageFormat        newFormat = null;
            List <ISupportedImageFormat> formats   = ImageProcessorBootstrapper.Instance.SupportedImageFormats.ToList();
            ISupportedImageFormat        format    = formats.FirstOrDefault(f => f.FileExtensions.Any(e => e.Equals(finalIdentifier, StringComparison.InvariantCultureIgnoreCase)));

            if (format != null)
            {
                // Return a new instance as we want to use instance properties.
                newFormat = Activator.CreateInstance(format.GetType()) as ISupportedImageFormat;

                if (newFormat != null)
                {
                    // I wish this wasn't hard-coded but there's no way I can
                    // find to preserve the palette.
                    if (identifier.Equals("png8"))
                    {
                        newFormat.IsIndexed = true;
                    }
                    else if (identifier.Equals("png"))
                    {
                        newFormat.IsIndexed = false;
                    }
                }
            }

            return(newFormat);
        }
        public void AlphaIsModified()
        {
            foreach (ImageFactory imageFactory in this.ListInputImages())
            {
                Image original = (Image)imageFactory.Image.Clone();
                imageFactory.Alpha(50);

                ISupportedImageFormat format = imageFactory.CurrentImageFormat;

                // The Image class does not support alpha transparency in bitmaps.
                if (format.GetType() == typeof(BitmapFormat))
                {
                    AssertionHelpers.AssertImagesAreIdentical(
                        original,
                        imageFactory.Image,
                        "because the alpha operation should not have been applied on {0}",
                        imageFactory.ImagePath);
                }
                else
                {
                    AssertionHelpers.AssertImagesAreDifferent(
                        original,
                        imageFactory.Image,
                        "because the alpha operation should have been applied on {0}",
                        imageFactory.ImagePath);
                }
            }
        }