Reputation: 120
I coded example from https://learn.microsoft.com/en-us/windows/uwp/audio-video-camera/custom-video-effects
Part of the code:
public void ProcessFrame(ProcessVideoFrameContext context)
{
using (CanvasBitmap inputBitmap = CanvasBitmap.CreateFromDirect3D11Surface(canvasDevice, context.InputFrame.Direct3DSurface))
using (CanvasRenderTarget renderTarget = CanvasRenderTarget.CreateFromDirect3D11Surface(canvasDevice, context.OutputFrame.Direct3DSurface))
using (CanvasDrawingSession ds = renderTarget.CreateDrawingSession())
{
var gaussianBlurEffect = new GaussianBlurEffect
{
Source = inputBitmap,
BlurAmount = (float)BlurAmount,
Optimization = EffectOptimization.Speed
};
ds.DrawImage(gaussianBlurEffect);
}
}
The problem is: i want to draw points (bitmaps) on frames but i have no idea how to pass specific coord to ProcessFrame function. On input i have x and y coords for every frame where to draw point and on the output i want to have video with added points for every frame. Thanks for help.
Upvotes: 1
Views: 490
Reputation: 1836
EDIT:
The code below is not suitable solution as the ProcessFrame(ProcessVideoFrameContext context)
is part of an interface implementation.
My next solution proposal is to create a custom effect, similar to the GaussianBlusEffect
and many more. An example here:
https://github.com/Microsoft/Win2D-Samples/blob/master/ExampleGallery
~~~ Below the original answer for reference.
You can pass in the X and Y parameters and access the pixels of the image.
public void ProcessFrame(ProcessVideoFrameContext context, int X, int Y)
{
using (CanvasBitmap inputBitmap = CanvasBitmap.CreateFromDirect3D11Surface(canvasDevice, context.InputFrame.Direct3DSurface))
using (CanvasRenderTarget renderTarget = CanvasRenderTarget.CreateFromDirect3D11Surface(canvasDevice, context.OutputFrame.Direct3DSurface))
using (CanvasDrawingSession ds = renderTarget.CreateDrawingSession())
{
Color[] Pixels = inputBitmap.GetPixelColors();
// Manipulate the array using X and Y with the Width parameter of the bitmap
var gaussianBlurEffect = new GaussianBlurEffect
{
Source = inputBitmap,
BlurAmount = (float)BlurAmount,
Optimization = EffectOptimization.Speed
};
ds.DrawImage(gaussianBlurEffect);
}
}
More info: https://microsoft.github.io/Win2D/html/M_Microsoft_Graphics_Canvas_CanvasBitmap_GetPixelColors.htm
I did not check if the Color[] is a pointer to the live buffer or a copy. If it is a copy, then you have to write back the buffer with SetPixelColors.
Upvotes: 1