c# - C# winforms .net 4.7 内存限制
问题描述
在我的项目中,我一一拍摄视频帧,将它们压缩为 1x1 像素,然后将其颜色存储在列表中。问题是,如果我以 25 fps 的速度拍摄约 9.5 分钟的视频,它只处理大约 15-20%,然后在使用 2gb 时内存不足。但我使用 64 位操作系统和处理器,我不知道如何为我的项目分配更多内存。此外,颜色列表将被快速读取(每秒 25-30 次),所以我不认为创建临时文件是一种选择,或者至少我想尝试分配更多的内存。所以,问题是:我如何为我的 .net 4.7 代码分配超过 2 GB 的空间?
我的图像处理代码:
List<Color> VideoFramesData = new List<Color>();
//fires when i click "parse" button in my form:
private void ParseVideoButton_Click(object sender, EventArgs e)
{
while (VideoReader.Read())
{
VideoFramesData.Add(CollapseBitmap(VideoReader.GetFrame()));
}
}
//Image downscaling function:
public Color CollapseBitmap(Bitmap bmp)
{
Color FrameColor;
Bitmap result = new Bitmap(1, 1);
Graphics g = Graphics.FromImage(result);
g.InterpolationMode = InterpolationMode.NearestNeighbor;
g.DrawImage(bmp, 0, 0, 1, 1);
FrameColor = result.GetPixel(0, 0);
result.Dispose();
g.Dispose();
return FrameColor;
}
解决方案
好的,确定了我的问题:我不是 Bitmap.Dispose'ing 的 bmp 函数参数,事实证明,你必须这样做。嗯,我知道的越多!
推荐阅读
- python - Python字符串索引错误'builten_function_or_method'和'object is not subscriptable'
- centos7 - 如何将 Jetty 9.4 配置为在公司代理后面工作?
- javascript - JS代码增加变量但只重新绘制一次二维码
- javascript - 使用geojson在openstreetmap中选择区域时如何添加子区域?
- ios - 环境对象的变化只通知订阅者一次
- postgresql - shared_buffers 的默认值是 8MB 吗?
- python - Sudo 命令不和谐机器人
- python - 2055:在 'localhost:3306' 处丢失与 MySQL 服务器的连接,系统错误:58 [ASN1] 嵌套 asn1 错误 (_ssl.c:4144)
- javascript - 引用另一个模型时,Mongoose 填充不起作用
- entity-framework-core - 删除子项时出现“实体之间的关联已被切断”错误,关系根据复合键定义