I am trying to use this code in my project but it appears that EditingSession
and FilterFactory
classes are no longer supported in SDK v1.2.115.0
Original code
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);
}
This is what I've attempted so far
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();
}
}
Error is raised because the ForegroundSource
of the BlendFilter is empty. The ForegroundSource
should be the result of the previous filters (in this case blurFilter and embossFilter), no?
But since I can't use EditingSession
and FilterFactory
, how do I properly change the code to work with the updated SDK?