首页 > 解决方案 > 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;
        }

标签: c#winformsram.net-4.7

解决方案


好的,确定了我的问题:我不是 Bitmap.Dispose'ing 的 bmp 函数参数,事实证明,你必须这样做。嗯,我知道的越多!


推荐阅读