admin管理员组文章数量:1433982
I attached video to canvas. On canvas user can draw line, rectangle etc. and these drawn object are hidden or visible according to time slice. Then user can save this video with that drawn object. I used the following code for this purpose. The issue is when I save it takes time almost equal to video length. How can I reduce this saving time or is there any other fast way save cropped canvas with drawn object
I used OpenCVSharp lib to create video from cropped canvas
Application.Current.Dispatcher.Invoke(() =>
{
canvas.VideoPlayer.mp1.Clock.Controller.SeekAlignedToLastTick(timeSpan1, System.Windows.Media.Animation.TimeSeekOrigin.BeginTime);
});
var writer = new VideoWriter(fileName, OpenCvSharp.FourCC.DIVX, frameRate, new OpenCvSharp.Size(vidSize.Width, vidSize.Height));
for (int i = startFrame; i < endFrame; i++)
{
CroppedBitmap croppedImage = new();
Application.Current.Dispatcher.Invoke(() =>
{
canvas.VideoPlayer.mp1.Position.Add(frameTimeInterval);
canvas.VideoPlayer.ShowHideToolsSaveAs(frame);
// --------> some time here it shows insufficient memeory when video is around 2 mins
RenderTargetBitmap rtb = new RenderTargetBitmap(width, height, 96d, 96d, PixelFormats.Default);
rtb.Render(canvas);
// create cropped image
croppedImage = new CroppedBitmap(rtb, vidSize);
});
if (croppedImage != null)
{
System.Drawing.Bitmap bmp = new(width, height);
byte[] byteArray = new byte[1];
Application.Current.Dispatcher.Invoke(() =>
{
bmp = BitmapFromSource(croppedImage);
byteArray = BitmapToByteArray(bmp);
});
Mat mat = new();
mat = BitmapConverter.ToMat(bmp);
writer.Write(mat);
}
本文标签: c wpf Saving images of cropped canvas in video takes much timeStack Overflow
版权声明:本文标题:c# wpf Saving images of cropped canvas in video takes much time - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745606701a2665877.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论