【发布时间】:2019-04-08 16:48:36
【问题描述】:
我正在截屏,将其缩小到分辨率的 50%,以减少空间,然后我将字节放入 buffer,但不幸的是,此过程需要太多时间。
目前,1920x1080 源分辨率需要 60 到 100 毫秒,这会导致 30fps 的输出视频速度加快,因为我生成屏幕截图的速度不够快。我需要达到大约 40 毫秒才能制作流畅的视频。
问题:如何应用更快的插值算法或限制所需的操作以加快速度?
public void Screenshot(byte[] buffer)
{
using (var bmp = new Bitmap(Params.SourceWidth, Params.SourceHeight))
{
using (var g = Graphics.FromImage(bmp))
{
g.CopyFromScreen(Point.Empty, Point.Empty, new Size(Params.SourceWidth, Params.SourceHeight), CopyPixelOperation.SourceCopy);
g.Flush();
using (Bitmap resized = new Bitmap(bmp, new Size(Params.TargetWidth, Params.TargetHeight)))
{
var bits = resized.LockBits(new Rectangle(0, 0, Params.TargetWidth, Params.TargetHeight), ImageLockMode.ReadOnly, PixelFormat.Format32bppRgb);
Marshal.Copy(bits.Scan0, buffer, 0, buffer.Length);
resized.UnlockBits(bits);
}
}
}
}
【问题讨论】:
-
就像我在您之前关于此主题的问题中所问的那样,现在已删除,只是为了说明上下文:您是否正在尝试发明自己的远程桌面协议?
-
@CodeCaster 不,我正在尝试以尽可能快的速度为
SharpAvi提供位图来记录桌面,而 60 毫秒 - 100 毫秒太慢了, -
你尝试过stackoverflow.com/questions/1922040/…中的任何选项吗?
-
你考虑过多线程吗?大多数现代台式机 CPU 都有多个内核。
标签: c# .net performance image-processing screenshot