我将自定义像素着色器效果应用于图像。
var eff = new Shaders.PixelateEffect();
eff.HorizontalPixelCounts = 15;
eff.VerticalPixelCounts = 15;
IMG1.Effect = eff;
然后我尝试在效果应用图像(IMG1)和另一个图像之间进行合并和叠加。(IMG2) 但是,IMG1.Source给我带来了原始图像。
ImageUtils.OverlayingImages(IMG1.Source, IMG2.Source, x, y);
如何获取更新的图像源? 当我旋转图像时它发生了同样的事情。 我需要使用RenderTargetBitmap捕获图像吗? 提前谢谢。
答案 0 :(得分:1)
我用RenderTargetBitmap解决了这个问题。无论如何,谢谢你的评论。
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);