0

I applied customized pixel-shader effect to an image.

var eff = new Shaders.PixelateEffect();
        eff.HorizontalPixelCounts = 15;
        eff.VerticalPixelCounts = 15;
        IMG1.Effect = eff;

Then I tried to merge and overlay between the effect applied image(IMG1) and another image.(IMG2) But, IMG1.Source bring me an original image.

ImageUtils.OverlayingImages(IMG1.Source, IMG2.Source, x, y);

How can I get an updated image source? it happened same when I rotate the image. Do I need to capture the image with RenderTargetBitmap? Thank you in advance.

Mark Choi
  • 420
  • 6
  • 16
  • Shader effects are applied the *rendering* of the affected element, not the element itself. I would think (hope?) it's possible to chain multiple shader effects together, in which case you could perform the merge/overlay in another shader, but you cannot capture the result in a `RenderTargetBitmap`, as the effects are applied at a later stage in the pipeline. I do not know any way of capturing the effect through WPF's own APIs, in fact, though you may be able to do a partial screen capture using unmanaged APIs. – Mike Strobel Feb 06 '18 at 17:08
  • Just giving idea, what if you apply effect after ImageUtils.OverlayingImages(IMG1.Source, IMG2.Source, x, y); – Gaurang Dave Feb 07 '18 at 05:53
  • @GaurangDave Umm.. I need to save all to a file ultimately. not only just showing on the screen. – Mark Choi Feb 07 '18 at 06:09

1 Answers1

1

I've solved it like this with RenderTargetBitmap. anyway, thank you for the comments.

var eff = new Shaders.PixelateEffect();
        eff.HorizontalPixelCounts = 15;
        eff.VerticalPixelCounts = 15;

        BitmapSource bitmap = (BitmapSource)IMG1.Source;
        var r = new Rectangle();
        r.Fill = new ImageBrush(bitmap);
        r.Effect = eff;

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

        var rtb = new RenderTargetBitmap(bitmap.PixelWidth, bitmap.PixelHeight, 96, 96
            , PixelFormats.Default);
        rtb.Render(r);

        // here's the updated source with the custom effect.
        IMG1.Source= ImageUtils.RenderTargetBitmapToBitmap(rtb);
Mark Choi
  • 420
  • 6
  • 16