Exemplo n.º 1
0
        public virtual void Add(BackgroundImageClass image)
        {
            if (ImageExclusionFilter != null && ImageExclusionFilter(image))
            {
                return;
            }

            var imageKey = new ImageMetadata(image);

            if (spriteList.Any(x => x.Key.Equals(imageKey)))
            {
                var originalImage = spriteList.First(x => x.Key.Equals(imageKey)).Value;
                var clonedImage   = new SpritedImage(originalImage.AverageColor, image, originalImage.Image)
                {
                    Position = originalImage.Position, Url = originalImage.Url, Metadata = imageKey
                };
                spriteList.Add(new KeyValuePair <ImageMetadata, SpritedImage>(imageKey, clonedImage));
                return;
            }
            SpritedImage spritedImage;
            var          sprite = spriteList.FirstOrDefault(x => x.Value.CssClass.ImageUrl == image.ImageUrl);

            if (sprite.Value != null)
            {
                image.IsSprite = true;
                sprite.Value.CssClass.IsSprite = true;
            }
            try
            {
                spritedImage          = SpriteContainer.AddImage(image);
                spritedImage.Metadata = imageKey;
            }
            catch (Exception ex)
            {
                var message = string.Format("There were errors reducing {0}", image.ImageUrl);
                Tracer.Trace(message);
                Tracer.Trace(ex.ToString());
                var wrappedException = new SpriteException(image.OriginalClassString, message, ex);
                Errors.Add(wrappedException);
                return;
            }
            spriteList.Add(new KeyValuePair <ImageMetadata, SpritedImage>(imageKey, spritedImage));
            if (SpriteContainer.Size >= config.SpriteSizeLimit || (SpriteContainer.Colors >= config.SpriteColorLimit && !config.ImageQuantizationDisabled && !config.ImageOptimizationDisabled))
            {
                Flush();
            }
        }
Exemplo n.º 2
0
        public virtual void Add(BackgroundImageClass image)
        {
            if (ImageExclusionFilter != null && ImageExclusionFilter(image)) return;

            var imageKey = new ImageMetadata(image);

            if (spriteList.Any(x => x.Key.Equals(imageKey)))
            {
                var originalImage = spriteList.First(x => x.Key.Equals(imageKey)).Value;
                var clonedImage = new SpritedImage(originalImage.AverageColor, image, originalImage.Image) { Position = originalImage.Position, Url = originalImage.Url, Metadata = imageKey };
                spriteList.Add(new KeyValuePair<ImageMetadata, SpritedImage>(imageKey, clonedImage));
                return;
            }
            SpritedImage spritedImage;
            var sprite = spriteList.FirstOrDefault(x => x.Value.CssClass.ImageUrl == image.ImageUrl);
            if(sprite.Value != null)
            {
                image.IsSprite = true;
                sprite.Value.CssClass.IsSprite = true;
            }
            try
            {
                spritedImage = SpriteContainer.AddImage(image);
                spritedImage.Metadata = imageKey;
            }
            catch (Exception ex)
            {
                var message = string.Format("There were errors reducing {0}", image.ImageUrl);
                Tracer.Trace(message);
                Tracer.Trace(ex.ToString());
                var wrappedException = new SpriteException(image.OriginalClassString, message, ex);
                Errors.Add(wrappedException);
                return;
            }
            spriteList.Add(new KeyValuePair<ImageMetadata, SpritedImage>(imageKey, spritedImage));
            if (SpriteContainer.Size >= config.SpriteSizeLimit || (SpriteContainer.Colors >= config.SpriteColorLimit && !config.ImageQuantizationDisabled && !config.ImageOptimizationDisabled))
                Flush();
        }