Tangibleidea
Tangibleidea

Reputation: 474

How can I get the object of effect-applied source

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.

Upvotes: 0

Views: 52

Answers (1)

Tangibleidea
Tangibleidea

Reputation: 474

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);

Upvotes: 1

Related Questions