简体   繁体   English

Bitmap.Save()方法异常

[英]Bitmap.Save() method exception

I am trying to write a windows application to convert .avi videos to bitmap frames. 我正在尝试编写一个Windows应用程序来将.avi视频转换为位图帧。 I am able to get the bitmaps but I am having problems saving them. 我能够获得位图但是我在保存它们时遇到了问题。

Frames are saved perfectly up to 1649th frame. 帧完美保存到第1649帧。 After that I get this exception: 之后我得到了这个例外:

Attempted to read or write protected memory. 尝试读取或写入受保护的内存。 This is often an indication that other memory is corrupt 这通常表明其他内存已损坏

I ran the code several times, the code always throw above exception when processing 1649th frame. 我运行了几次代码,代码在处理第1649帧时总是抛出异常。 The output folder is empty at the beginning and its size is 389 MBs when the program stops. 输出文件夹在开头为空,程序停止时其大小为389 MB。

I am guessing that windows do not allow a program to write this amount of data in a short interval but I am not sure and I don't know how to fix it. 我猜测窗口不允许程序在短时间内写入这些数据,但我不确定,我不知道如何修复它。 Can anyone help? 有人可以帮忙吗?

for(counter = reader.Start; counter<(reader.Start + reader.Length); counter++)
{
    DummyBitmap = reader.GetNextFrame();
    DummyBitmap.Save(folderBrowserDialog2.SelectedPath + "\\" + counter.ToString()      + ".bmp");
    reader.Position++;
}

Bitmap class implements IDisposable interface so it would be wise to use it as: Bitmap类实现了IDisposable接口,因此最好将它用作:

using (var b = new Bitmap(...))
{

}

Also, maybe this post can give you some answers: Bitmap memory leak . 此外,也许这篇文章可以给你一些答案: 位图内存泄漏

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM