nokia Imaging SDK customize BlendFilter

穿精又带淫゛_ 提交于 2019-12-12 01:14:35

问题


I have created this code

Uri _blendImageUri = new Uri(@"Assets/1.png", UriKind.Relative);
var _blendImageProvider = new StreamImageSource((System.Windows.Application.GetResourceStream(_blendImageUri).Stream));

var bf = new BlendFilter(_blendImageProvider);

Filter work nice. But I want change image size for ForegroundSource property. How can I load image with my size?


回答1:


If I understood you correctly you are trying to blend ForegroundSource with only a part of the original image? That is called local blending at it is currently not supported on the BlendFilter itself.

You can however use ReframingFilter to reframe the ForegroundSource and then blend it. Your chain will look like something like this:

using (var mainImage = new StreamImageSource(...))
using (var filterEffect = new FilterEffect(mainImage))
{
    using (var secondaryImage = new StreamImageSource(...))
    using (var secondaryFilterEffect = new FilterEffect(secondaryImage))
    using (var reframing = new ReframingFilter(new Rect(0, 0, 500, 500), 0))    //reframe your image, thus "setting" the location and size of the content when blending
    {
        secondaryFilterEffect.Filters = new [] { reframing };

        using (var blendFilter = new BlendFilter(secondaryFilterEffect)
        using (var renderer = new JpegRenderer(filterEffect))
        {
            filterEffect.Filters = new [] { blendFilter };

            await renderer.RenderAsync();
        }
    }
}

As you can see, you can use the reframing filter to position the content of your ForegroundSource so that it will only blend locally. Note that when reframeing you can set the borders outside of the image location (for example new Rect(-100, -100, 500, 500)) and the areas outside of the image will appear as black transparent areas - exactly what you need in BlendFilter.



来源:https://stackoverflow.com/questions/21531492/nokia-imaging-sdk-customize-blendfilter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!