Pergunta

so I have this code here that pulls out the frames from an AVI file, makes a clone of them, and stores them in an array. After a few hundred times, I get an error saying "Parameter is not valid." I've searched around for answers, but all the answers are for when something works once, but then doesn't work again. This one on average executes these lines 490 times before this error occurs. I was wondering if one of you could tell me what's wrong here? Also, the file = null is actually changed later down in the code to have a value, in case you would think that's where I got the error.

Help: I'm using AForge.Video.VFW; for the AVIWriter and Reader, and I'm calling that void in a different thread.

Sorry if this isn't good enough. This is the first question I've ever asked on here.

AVIWriter writer = new AVIWriter("wmv3");
AVIReader reader = new AVIReader();
string file = null;
Bitmap[] AVIImages = new Bitmap[1];

int imagesProcessed = 0;
double progressValue = 0;

private void getImages()
{
    reader.Open(file);
    while (reader.Position - reader.Start < reader.Length)
    {
        Application.DoEvents();
        AVIImages[imagesProcessed] = (Bitmap)reader.GetNextFrame().Clone();
        imagesProcessed++;
        progressValue = (int)((double)imagesProcessed / (double)reader.Length * 100);
        Array.Resize(ref AVIImages, imagesProcessed + 1);
        Thread.Sleep(10);
    }
    reader.Close();
    picWaiting.Visible = false;
    lblWaiting.Text = "Done!";
    timeUpdateProgressBar.Stop();
}
Foi útil?

Solução

C# "Parameter is not valid." creating new bitmap

Seems to be why this happens too much memory is wasted on the Bitmaps, can't store too much bitmaps at one time.

You say you create 490 Bitmaps.. figure out the limit and either stop there or start overwriting the old bitmaps

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top