我正在尝试将Lumia.Imaging SDK CropEffect与BlendEffect结合使用来裁剪一个图像并覆盖另一个图像。
这个问题是CropEffect似乎接受我的rect并输出一个设置为我的rect的有效区域的图像时,当我缩放并使用BlendEffect.TargetArea()返回IImageProvider时,它实际上并未修剪多余的含义。图像的多余修剪部分可见。
如何完全切除作物的外部或设置BlendEffect以忽略作物矩形以外的区域?
假设我正在喂食的cropRect
正在将输入框的宽度裁切%50,则TargetArea然后应将裁切部分居中,而应将应该裁切的右侧区域代替继续并覆盖背景。
class ForgroundAndBackgroundBlendEffect : EffectGroupBase
{
private BlendEffect _blendEffect;
private BlendEffect _forgroundOverlayEffect;
private ChromaKeyEffect _chromakeyEffect;
private CropEffect _cropEffect;
public ForgroundAndBackgroundBlendEffect(Color color, double colorDistance, double noiseSuppression, Rect cropRect)
{
_cropEffect = new CropEffect(cropRect);
_chromakeyEffect = new ChromaKeyEffect(color, colorDistance, noiseSuppression);
_chromakeyEffect.Source = _cropEffect;
_blendEffect = new BlendEffect();
_blendEffect.ForegroundSource = _chromakeyEffect;
_blendEffect.TargetArea = new Rect(new Point(.25, 0), new Point(.75, 1));
_forgroundOverlayEffect = new BlendEffect();
_forgroundOverlayEffect.Source = _blendEffect;
}
public IImageProvider BackgroundSource
{
get { return _blendEffect.Source; }
set { _blendEffect.Source = value; }
}
public IImageProvider ForgroundSource
{
get { return _forgroundOverlayEffect.ForegroundSource; }
set { _forgroundOverlayEffect.ForegroundSource = value; }
}
protected override IImageProvider PrepareGroup(IImageProvider groupSource)
{
_cropEffect.Source = groupSource;
return _forgroundOverlayEffect;
}
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
_forgroundOverlayEffect.Dispose();
_blendEffect.Dispose();
}
}