Esempio n. 1
0
        public void LoadImage(PipelineElement reader, float opacity = 1, FileFormat fileFormat = FileFormat.Tiff, bool actualSize = false, bool preserveAspectRatio = false)
        {
            string storageId;

            using (var stream = new MemoryStream())
                using (var writer = ImageWriter.Create(fileFormat, stream))
                {
                    if (writer is TiffWriter)
                    {
                        (writer as TiffWriter).Compression = CompressionType.Zip;
                    }

                    var pipeline = new Pipeline(reader);

                    if (!Utils.EqualsOfFloatNumbers(opacity, 1f))
                    {
                        var scaleAlpha = new ScaleAlpha(opacity);
                        pipeline.Add(scaleAlpha);
                    }

                    pipeline.Add(writer);

                    pipeline.Run();
                    pipeline.Remove(reader);
                    pipeline.DisposeAllElements();

                    stream.Position = 0;

                    storageId = Configuration.FileCache.AddFile(Common.GetImageExtension(fileFormat), stream, true);
                }

            LoadImage(storageId, actualSize, preserveAspectRatio);
        }
Esempio n. 2
0
        public void ExtendPipeline(Pipeline pipeline, IImageParams destImageParams, ColorManagement colorManagement, float scale, out IEnumerable <IDisposable> deps)
        {
            deps = new List <IDisposable>();

            pipeline.Add(GetShapeDrawer(destImageParams, colorManagement, scale));

            var scaleAlpha = new ScaleAlpha(Opacity);
            var combiner   = GetImageCombiner(destImageParams, colorManagement, scale, deps, scaleAlpha);

            if (combiner != null)
            {
                pipeline.Add(combiner);
            }
        }
Esempio n. 3
0
        internal Combiner GetImageCombiner(IImageParams destImageParams, ColorManagement colorManagement, float scale, IEnumerable <IDisposable> deps, ScaleAlpha alpha)
        {
            if (!Configuration.FileCache.FileExists(SourceFileId))
            {
                return(null);
            }

            var imageStream = Configuration.FileCache.GetReadStream(SourceFileId, true);

            ((IList)deps).Add(imageStream);

            var reader = ImageReader.Create(imageStream);

            ((IList)deps).Add(reader);

            IImageParams firstElement;
            var          psdReader = reader as PsdReader;

            if (psdReader != null)
            {
                firstElement = psdReader.MergedImageFrame;
            }
            else
            {
                firstElement = reader;
            }

            var pipeline = new Pipeline((PipelineElement)firstElement);

            var dpi       = destImageParams.DpiX * scale;
            var imageRect = GetImageRectangle(dpi);

            if (firstElement.Width != imageRect.Width || firstElement.Height != imageRect.Height)
            {
                pipeline.Add(new Resize(imageRect.Width, imageRect.Height, _resizeInterpolationMode));
            }

            if (alpha != null)
            {
                pipeline.Add(alpha);
            }

            // Convert color of image
            var colorConverter = ColorManagement.GetColorConverter(colorManagement, firstElement, destImageParams);

            if (colorConverter != null)
            {
                pipeline.Add(colorConverter);
            }

            if (!Angle.Equals(0))
            {
                // Don't rotate bitmap without alpha channel.
                if (!firstElement.PixelFormat.HasAlpha)
                {
                    // Add alpha channel if scaleAlpha or color conversion does not add it
                    if (alpha == null && (colorConverter == null || !colorConverter.DestinationPixelFormat.HasAlpha))
                    {
                        pipeline.Add(new SetAlpha(1));
                    }
                }

                var rotate = new MatrixTransform
                {
                    Matrix            = Matrix.CreateRotate((float)Angle),
                    InterpolationMode = InterpolationMode.High,
                    BackgroundColor   = ColorManagement.GetTransparentColor(destImageParams.PixelFormat)
                };

                pipeline.Add(rotate);
            }

            var imageLocation = GetDrawingRectangle(dpi).Bounds.Location;
            var imageCombiner = new Combiner(CombineMode.AlphaOverlay, pipeline, true)
            {
                X = (int)imageLocation.X,
                Y = (int)imageLocation.Y
            };

            return(imageCombiner);
        }