상속: SoundInTheory.DynamicImage.DirtyTrackingObject
예제 #1
0
파일: Image.cs 프로젝트: dpawatts/zeus
        public string GetUrl(int width, int height, bool fill, DynamicImageFormat format)
        {
            Composition image = new Composition();
            image.ImageFormat = format;
            ImageLayer imageLayer = new ImageLayer();

            ZeusImageSource source = new ZeusImageSource();
            source.ContentID = ID;

            imageLayer.Source = source;

            ResizeFilter resizeFilter = new ResizeFilter();
            resizeFilter.Mode = fill ? ResizeMode.UniformFill : ResizeMode.Uniform;
            resizeFilter.Width = Unit.Pixel(width);
            resizeFilter.Height = Unit.Pixel(height);

            imageLayer.Filters.Add(resizeFilter);

            image.Layers.Add(imageLayer);

            return ImageUrlGenerator.GetImageUrl(image);

            /*old code replaced
             *
            return new DynamicImageBuilder()
                .WithLayer(
                    LayerBuilder.Image.SourceImage(this).WithFilter(FilterBuilder.Resize.To(width, height, fill)))
                .Url;
             */
        }
예제 #2
0
        public Bitmap GetBitmap()
        {
            Di.Composition composition = new Di.Composition();
            composition.Fill.Type            = Di.FillType.Solid;
            composition.Fill.BackgroundColor = Di.Colors.Transparent;
            composition.ImageFormat          = Di.DynamicImageFormat.Png;

            foreach (Layer layer in Layers)
            {
                Di.Layers.ImageLayer imgLayer = new Di.Layers.ImageLayer();
                imgLayer.BlendMode = (Di.BlendMode)layer.BlendMode;
                imgLayer.Source    = layer.Image.ToImageImageSource();

                if (layer.IsMasked)
                {
                    Di.Filters.ClippingMaskFilter mask = new Di.Filters.ClippingMaskFilter();
                    mask.MaskImage = layer.Mask.ToImageImageSource();
                    mask.Enabled   = true;
                    imgLayer.Filters.Add(mask);
                }
                if (layer.Opacity < 100.0)
                {
                    Di.Filters.OpacityAdjustmentFilter opacity = new Di.Filters.OpacityAdjustmentFilter();
                    opacity.Opacity = (byte)layer.Opacity;
                    opacity.Enabled = true;
                    imgLayer.Filters.Add(opacity);
                }

                foreach (Modifier modifier in layer.Modifiers)
                {
                    imgLayer.Filters.Add(modifier.GetFilter());
                }

                int w = layer.Image.Width;
                if (layer.Width > 0)
                {
                    w = layer.Width;
                }
                int h = layer.Image.Height;
                if (layer.Height > 0)
                {
                    h = layer.Height;
                }
                imgLayer.Filters.Add(GetScaleFilter(w, h, layer.FittingMode));

                imgLayer.Filters.Add(GetRotationFilter(layer.Angle));

                imgLayer.X = layer.X;
                imgLayer.Y = layer.Y;

                composition.Layers.Add(imgLayer);
            }

            return(composition.GenerateImage().Image.ToBitmap());
        }
예제 #3
0
        /// <summary>
        /// Gets the properties for the specified image, respecting caching settings.
        /// </summary>
        /// <param name="composition"></param>
        /// <returns></returns>
        public static ImageProperties GetImageProperties(Composition composition)
        {
            string cacheKey = composition.GetCacheKey();

            ImageProperties imageProperties;
            if (!DynamicImageCacheManager.Exists(cacheKey))
            {
                CompositionImage compositionImage = composition.GetCompositionImage(cacheKey);
                if (compositionImage.Properties.IsImagePresent || DynamicImageCacheManager.StoreMissingImagesInCache)
                {
                    Dependency[] dependencies = composition.GetDependencies().Distinct().ToArray();
                    DynamicImageCacheManager.Add(cacheKey, compositionImage, dependencies);
                }

                imageProperties = compositionImage.Properties;
            }
            else
            {
                imageProperties = DynamicImageCacheManager.GetProperties(cacheKey);
            }

            return imageProperties;
        }
예제 #4
0
        public string GetUrl(int width, int height, bool fill, DynamicImageFormat format, bool isResize)
        {
            //first construct the crop
            var imageSource = new ZeusImageSource();
            imageSource.ContentID = this.ID;

            if (this.Data == null)
                return "";

            // generate resized image url
            // set image format
            var dynamicImage = new SoundInTheory.DynamicImage.Composition();
            dynamicImage.ImageFormat = format;

            // create image layer wit ha source
            var imageLayer = new ImageLayer();
            imageLayer.Source = imageSource;

            // add filters
            if (!(TopLeftXVal == 0 && TopLeftYVal == 0 && CropWidth == 0 && CropHeight == 0))
            {
                var cropFilter = new CropFilter
                {
                    Enabled = true,
                    X = this.TopLeftXVal,
                    Y = this.TopLeftYVal,
                    Width = this.CropWidth,
                    Height = this.CropHeight
                };
                if (!isResize)
                    imageLayer.Filters.Add(cropFilter);
            }

            if (width > 0 && height > 0)
            {
                var resizeFilter = new ResizeFilter
                {
                    Mode = isResize ? ResizeMode.Uniform : ResizeMode.UniformFill,
                    Width = SoundInTheory.DynamicImage.Unit.Pixel(width),
                    Height = SoundInTheory.DynamicImage.Unit.Pixel(height)
                };
                imageLayer.Filters.Add(resizeFilter);
            }
            else if (width > 0)
            {
                var resizeFilter = new ResizeFilter
                {
                    Mode = ResizeMode.UseWidth,
                    Width = SoundInTheory.DynamicImage.Unit.Pixel(width)
                };
                imageLayer.Filters.Add(resizeFilter);
            }
            else if (height > 0)
            {
                var resizeFilter = new ResizeFilter
                {
                    Mode = ResizeMode.UseHeight,
                    Height = SoundInTheory.DynamicImage.Unit.Pixel(height)
                };
                imageLayer.Filters.Add(resizeFilter);
            }

            // add the layer
            dynamicImage.Layers.Add(imageLayer);

            // generate url
            return ImageUrlGenerator.GetImageUrl(dynamicImage);
        }