Inheritance: System.Windows.Media.Effects.ShaderEffect
Exemple #1
0
        public void Run(TextWriter runscript)
        {
            Shader shader;
            if (CreateShader != null)
                shader = CreateShader (this);
            else
                shader = new Shader (Effect);

            BitmapImage bitmap = new BitmapImage (new Uri (Driver.MakePath (InputFile)));

            string reference = string.Format ("references/{0}.png", TestName);

            double t = Tolerance == 0 ? DefaultTolerance : Tolerance;

            Apply (shader, bitmap, reference);
            runscript.WriteLine ("{0} {1} {2} {3} {4} {5} {6} {7}", TestName, Effect, InputFile, reference, t, ExtraArgs);
        }
Exemple #2
0
        static void Apply(Shader shader, BitmapImage bitmap, string destImage)
        {
            Rectangle r = new Rectangle ();
            r.Effect = shader;
            shader.Input = new ImageBrush (bitmap);
            /*The fill brush is ignored due to the effect been applied*/
            r.Fill = new SolidColorBrush (Colors.Aquamarine);

            Size size = new Size (bitmap.PixelWidth, bitmap.PixelHeight);
            r.Measure (size);
            r.Arrange (new Rect (size));

            RenderTargetBitmap render = new RenderTargetBitmap (
                bitmap.PixelWidth,
                bitmap.PixelHeight,
                96,
                96,
                PixelFormats.Pbgra32);

            render.Render (r);

            PngBitmapEncoder png = new PngBitmapEncoder ();
            png.Frames.Add (BitmapFrame.Create (render));
            using (Stream stm = File.Open (destImage, FileMode.OpenOrCreate)) {
                png.Save (stm);
            }
        }