缺少EditingSession和FilterFactory在诺基亚成像SDK v1.2.115.0 HDR的例子

本文关键字:HDR v1 SDK EditingSession FilterFactory 成像 诺基亚 缺少 | 更新日期: 2023-09-27 18:08:49

我试图在我的项目中使用此代码,但似乎在SDK v1.2.115.0中不再支持EditingSessionFilterFactory

原始代码

WriteableBitmap toneMap1 = new WriteableBitmap(CapturedImage.PixelWidth, CapturedImage.PixelHeight);
using (EditingSession editsession = new EditingSession(image1.AsBitmap()))
using (EditingSession blendSession = new EditingSession(image1.AsBitmap()))
{
// Create the blurred version of original image
editsession.AddFilter(FilterFactory.CreateBlurFilter(BlurLevel.Blur1));
// Perform the difference between the original image and the blurred copy
editsession.AddFilter(FilterFactory.CreateBlendFilter(blendSession, BlendFunction.Difference));               
// Create the Laplacian of the original image using the emboss filter
blendSession.AddFilter(FilterFactory.CreateEmbossFilter(1.0f));
// Add the result of blur with emboss filter
editsession.AddFilter(FilterFactory.CreateBlendFilter(blendSession, BlendFunction.Add));
// Perform a gray scale as we need just informations on radiance not colours
editsession.AddFilter(FilterFactory.CreateGrayscaleFilter());
// Render the result
await editsession.RenderToWriteableBitmapAsync(toneMap1, OutputOption.PreserveAspectRatio);
}

这是我到目前为止所尝试的

        IList<IFilter> filtersList = new List<IFilter>();
        var blurFilter = new BlurFilter()
        { 
            BlurRegionShape = BlurRegionShape.Rectangular,
            KernelSize = 10
        };

        var blendFilter = new BlendFilter()
        {
            BlendFunction = BlendFunction.Difference,                
        };
        var embossFilter = new EmbossFilter()
        {
            Level = 1.0f
        };
        var blendFilter2 = new BlendFilter()
        {
            BlendFunction = BlendFunction.Add
        };
        var grayScaleFilter = new GrayscaleFilter();
        filtersList.Add(blurFilter);
        filtersList.Add(blendFilter);
        filtersList.Add(embossFilter);
        filtersList.Add(blendFilter2);
        filtersList.Add(grayScaleFilter);

            using (var ms = new MemoryStream())
            {
                image1.SaveJpeg(ms, image1.PixelWidth, image1.PixelHeight, 0, 100);
                ms.Position = 0;
                using (var streamImageSource1 = new StreamImageSource(ms))
                using (var filterEffect1 = new FilterEffect(streamImageSource1) { Filters = filtersList })
                using (var writableBitmapRenderer1 = new WriteableBitmapRenderer(filterEffect1, toneMap1))
                {
                    toneMap1 = await writableBitmapRenderer1.RenderAsync();
                }
            }
由于BlendFilter的ForegroundSource为空,引发

错误。ForegroundSource应该是以前过滤器的结果(在这种情况下是blurFilter和embossFilter),不是吗?

但是由于我不能使用EditingSessionFilterFactory,我如何正确地更改代码以使用更新的SDK?

缺少EditingSession和FilterFactory在诺基亚成像SDK v1.2.115.0 HDR的例子

我想我明白了。对于那些在同一条船上的人,这是我所做的

            using (var ms = new MemoryStream())
            {
                image2.SaveJpeg(ms, image2.PixelWidth, image2.PixelHeight, 0, 100);
                ms.Position = 0;
                using (var oriStreamImageSource2 = new StreamImageSource(ms))
                {
                    //Create the blurred version of original image
                    var blurEffect = new FilterEffect(oriStreamImageSource2)
                    {
                        Filters = new[] { new BlurFilter() { KernelSize = BlurLevel } }
                    };
                    var blendEffect1 = new FilterEffect(blurEffect)
                    {
                        Filters = new[] { new BlendFilter(oriStreamImageSource2, BlendFunction.Difference) }
                    };
                    //Create the Laplacian of the original image using the emboss filter
                    var embossEffect = new FilterEffect(oriStreamImageSource2)
                    {
                        Filters = new[] { new EmbossFilter(1.0f) }
                    };
                    //Add the result of blur with emboss filter
                    var blendEffect2 = new FilterEffect(blendEffect1)
                    {
                        Filters = new[] { new BlendFilter(embossEffect, BlendFunction.Add) }
                    };
                    //Perform a gray scale as we need just informations on radiance not colours
                    var grayScaleEffect = new FilterEffect(blendEffect2)
                    {
                        Filters = new[] { new GrayscaleFilter() }
                    };
                    using (var writableBitmapRenderer = new WriteableBitmapRenderer(grayScaleEffect, toneMap2))
                    {
                        toneMap2 = await writableBitmapRenderer.RenderAsync();
                        blurEffect.Dispose();
                        blendEffect1.Dispose();
                        embossEffect.Dispose();
                        blendEffect2.Dispose();
                        grayScaleEffect.Dispose();
                    }
                };
            }