예제 #1
0
        /// <summary>
        /// Function to initialize the view from the data context.
        /// </summary>
        /// <param name="dataContext">The data context to use.</param>
        private void InitializeFromDataContext(IImageContent dataContext)
        {
            if (dataContext == null)
            {
                ResetDataContext();
                return;
            }

            _ribbonForm.SetDataContext(dataContext);
            CropResizeSettings.SetDataContext(dataContext.CropOrResizeSettings);
            DimensionSettings.SetDataContext(dataContext.DimensionSettings);
            GenMipMapSettings.SetDataContext(dataContext.MipMapSettings);
            SetAlpha.SetDataContext(dataContext.AlphaSettings);
        }
예제 #2
0
    /// <summary>
    /// Tints using alpha channel and memory-friendly Pipeline API
    /// </summary>
    private static void TintUsingAlphaMemoryFriendly(RgbColor color)
    {
        // reader  --->  converter  ---> invert  -----\
        //                            generator  --->  setAlpha  --->  removeAlpha  --->  writer
        using (var reader = ImageReader.Create("../../../../_Input/Chicago.jpg"))
            using (var converter = new ColorConverter(PixelFormat.Format8bppGrayscale))
                using (var invert = new Invert())
                    using (var generator = new ImageGenerator(reader.Width, reader.Height, PixelFormat.Format24bppRgb, color))
                        using (var setAlpha = new SetAlpha())
                            using (var removeAlpha = new RemoveAlpha(RgbColor.White))
                                using (var writer = ImageWriter.Create("../../../../_Output/TintUsingAlphaMemoryFriendly_" + color.ToString() + ".jpg"))
                                {
                                    setAlpha.AlphaSource = reader + converter + invert;

                                    Pipeline.Run(generator + setAlpha + removeAlpha + writer);
                                }
    }
    /// <summary>
    /// Adds alpha channel using memory-friendly Pipeline API
    /// </summary>
    private static void AddAlphaChannelMemoryFriendly()
    {
        // reader --------------->  setAlpha  --->  writer
        // alpha  --->  drawer  ---/
        using (var reader = ImageReader.Create("../../../../_Input/Chicago.jpg"))
            using (var alpha = new ImageGenerator(reader.Width, reader.Height, PixelFormat.Format8bppGrayscale, new GrayscaleColor(0)))
                using (var drawer = new Drawer())
                    using (var setAlpha = new SetAlpha())
                        using (var writer = ImageWriter.Create("../../../../_Output/AddAlphaChannelMemoryFriendly.png"))
                        {
                            drawer.Draw += (sender, e) =>
                            {
                                e.Graphics.FillEllipse(new SolidBrush(new GrayscaleColor(255)),
                                                       0, 0, reader.Width, reader.Height);
                            };

                            setAlpha.AlphaSource = alpha + drawer;

                            Pipeline.Run(reader + setAlpha + writer);
                        }
    }