我被委托创建一个“Cinemagraph”功能,用户必须使用
例如:
我考虑获取
如何操作?我可以轻松地从磁盘加载图像,但是如何根据笔画剪切图像?
更多细节:
在绘制和选择要保留静态的像素后,我有一个
基于合并的
目前为止我的代码:
InkCanvas
选择所需区域,以绘制应保留未更改的选定像素,以用于其余动画/视频(或选择应为“活动”的像素)。例如:
![From Johan Blomström](https://istack.dev59.com/8X4E0.gif)
InkCanvas
中的Stroke
集合,并使用它来剪切图像并与未更改的图像合并。如何操作?我可以轻松地从磁盘加载图像,但是如何根据笔画剪切图像?
更多细节:
在绘制和选择要保留静态的像素后,我有一个
Stroke
集合。我可以获取每个单独Stroke
的Geometry
,但我可能需要合并所有几何图形。基于合并的
Geometry
,我需要反转(Geometry
),然后使用它来剪切我的第一帧,稍后将剪切好的图像与所有其他帧合并。目前为止我的代码:
//Gets the BitmapSource from a String path:
var image = ListFrames[0].ImageLocation.SourceFrom();
var rectangle = new RectangleGeometry(new Rect(new System.Windows.Point(0, 0), new System.Windows.Size(image.Width, image.Height)));
Geometry geometry = Geometry.Empty;
foreach(Stroke stroke in CinemagraphInkCanvas.Strokes)
{
geometry = Geometry.Combine(geometry, stroke.GetGeometry(), GeometryCombineMode.Union, null);
}
//Inverts the geometry, to clip the other unselect pixels of the BitmapImage.
geometry = Geometry.Combine(geometry, rectangle, GeometryCombineMode.Exclude, null);
//This here is UIElement, I can't use this control, I need a way to clip the image without using the UI.
var clippedImage = new System.Windows.Controls.Image();
clippedImage.Source = image;
clippedImage.Clip = geometry;
//I can't get the render of the clippedImage control because I'm not displaying that control.
有没有一种方法可以在不使用UIElement的情况下剪切BitmapSource?
也许可以
我在考虑OpacityMask和brush…但是我不能使用UIElement,我需要直接应用OpacityMask到BitmapSource。