C#System.OutOfMemoryException:'内存不足'。 [英] C# System.OutOfMemoryException: 'Out of memory.'

查看:1542
本文介绍了C#System.OutOfMemoryException:'内存不足'。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用AForge的videoSourcePlayer。现在我不得不为它添加一个函数,因为GetCurrentVideoFrame()不能正常工作我需要的原因。所以我创建一个名为GetCurrent()的
函数,它按照我想要的方式工作。我遇到的问题是当我使用它代替GetCurrentVideoFrame()时,我得到一个System.OutOfMemoryException:'内存不足。'例外,我没有理想的原因。这是我的代码:


 Bitmap getPic2(int i2)
{
位图bmp = null;
位图tempB = null;
if(endIRList [i2] .X> videoSourcePlayer.Width - 1)
endIRList [i2] = new System.Drawing.Point(videoSourcePlayer.Width - 1,endIRList [i2] .Y);
if(endIRList [i2] .Y> videoSourcePlayer.Height - 1)
endIRList [i2] = new System.Drawing.Point(endIRList [i2] .X,videoSourcePlayer.Height - 1);
if(stIRList [i2] .X> = 0&& stIRList [i2] .Y> = 0&& endIRList [i2] .X< videoSourcePlayer.Width&& endIRList [i2] .Y< videoSourcePlayer.Height)
{
if(endIRList [i2] .X - stIRList [i2] .X> 0&& endIRList [i2] .Y - stIRList [i2] .Y> 0)
{
bmp = videoSourcePlayer.GetCurrent();
System.Drawing.Image iOld = p2.Image;
tempB = bmp.Clone(new Rectangle(stIRList [i2] .X,stIRList [i2] .Y,endIRList [i2] .X - stIRList [i2] .X,endIRList [i2] .Y - stIRList [ 12] .Y),bmp.PixelFormat);

if(iOld!= null)
{
iOld.Dispose();
iOld = null;
}
}
}
pictureBox1.Image = this.videoSourcePlayer.GetCurrent();

TestPicBox.Image = tempB;


返回tempB;
}

我遇到的问题是:






   tempB   =   bmp   克隆   new     Rectangle    stIRList   [  i2  ]。  X    stIRList   [  i2  ]。  Y    endIRList   [  i2  ]。  X    -    stIRList   [  i2  ]。  X    endIRList   [  i2  ]。  Y    -    stIRList   [  i2  ]。  Y  ),  bmp    PixelFormat  );   

解决方案

我正在使用AForge的videoSourcePlayer。现在我不得不为它添加一个函数,因为GetCurrentVideoFrame()不能正常工作我所需要的。所以我创建了一个名为GetCurrent()的
函数按照我想要的方式工作。我遇到的问题是当我用它代替GetCurrentVideoFrame()时,我得到一个System.OutOfMemoryException:'内存不足。'例外,我没有理想的原因。这是我的代码:

 Bitmap getPic2(int i2)
{
Bitmap bmp = null;
Bitmap tempB = null;
if(endIRList [i2] .X> videoSourcePlayer.Width - 1)
endIRList [i2] = new System.Drawing.Point(videoSourcePlayer.Width - 1,endIRList [i2] .Y);
if(endIRList [i2] .Y> videoSourcePlayer.Height - 1)
endIRList [i2] = new System.Drawing.Point(endIRList [i2] .X,videoSourcePlayer.Height - 1);
if(stIRList [i2] .X> = 0&& stIRList [i2] .Y> = 0&& endIR列表[i2] .X< videoSourcePlayer.Width&& endIRList [i2] .Y< videoSourcePlayer.Height)
{
if(endIRList [i2] .X - stIRList [i2] .X> 0&& endIRList [i2] .Y - stIRList [i2] .Y> 0)
{
bmp = videoSourcePlayer.GetCurrent();
System.Drawing.Image iOld = p2.Image;
tempB = bmp.Clone(new Rectangle(stIRList [i2] .X,stIRList [i2] .Y,endIRList [i2] .X - stIRList [i2] .X,endIRList [i2] .Y - stIRList [ 12] .Y),bmp.PixelFormat);

if(iOld!= null)
{
iOld.Dispose();
iOld = null;
}
}
}
pictureBox1.Image = this.videoSourcePlayer.GetCurrent();

TestPicBox.Image = tempB;


返回tempB;
}

我遇到的问题是:

   tempB   =   bmp    Clone    new    < span class ="typ"style ="margin:0px; padding:0px; border:0px; vertical-align:baseline; color:#2b91af; font-style:inherit; font-variant:inherit; font-weight:inherit; line-height:inherit; font-family:inherit"> Rectangle    stIRList   [  i2  ]。  X    stIRList   [  i2  ]。  Y    endIRList   [  i2  ]。  X    -    stIRList   [  i2  ]。  X    endIRList   [  i2  ]。  Y    -    stIRList   [  i2  ]。  Y  ),  bmp    PixelFormat  );   



现在如果我只是使用bmp = GetCurrentVideoFrame我没有遇到问题。所以我的函数GetCurrentVideo出现问题



这里是代码:

 public Bitmap GetCurrentVideoFrame()
{
lock(sync)
{
return(currentFrame == null)?null:AForge.Imaging.Image.Clone(currentFrame);
}
}

public Bitmap GetCurrent ()
{
lock(sync)
{

Bitmap original = GetCurrentVideoFrame();
currentPic = new Bitmap(original,new Size(original) .Width / 2,original.Height / 2));
original.Dispose();
original = null;
return currentPic;
}

}




我只是看不出为什么他们的功能有效而且我没有。有人可以帮忙吗?









I am using videoSourcePlayer from AForge. now I had to add a function to it because GetCurrentVideoFrame( ) was not working the why I needed. So I make a function called GetCurrent() and it work the way I wanted. The problem I am having is when I used it in place of GetCurrentVideoFrame( ) I get a System.OutOfMemoryException: 'Out of memory.' Exception and I have no Ideal why. here is my code :

Bitmap getPic2(int i2)
    {
        Bitmap bmp = null;
        Bitmap tempB = null;
        if (endIRList[i2].X > videoSourcePlayer.Width - 1)
            endIRList[i2]= new System.Drawing.Point(videoSourcePlayer.Width - 1, endIRList[i2].Y);
        if (endIRList[i2].Y > videoSourcePlayer.Height - 1)
            endIRList[i2] = new System.Drawing.Point(endIRList[i2].X, videoSourcePlayer.Height - 1);
        if (stIRList[i2].X >= 0 && stIRList[i2].Y >= 0 && endIRList[i2].X < videoSourcePlayer.Width && endIRList[i2].Y < videoSourcePlayer.Height)
        {
            if (endIRList[i2].X - stIRList[i2].X > 0 && endIRList[i2].Y - stIRList[i2].Y > 0)
            {
                bmp = videoSourcePlayer.GetCurrent();
                System.Drawing.Image iOld = p2.Image;
                tempB = bmp.Clone(new Rectangle(stIRList[i2].X, stIRList[i2].Y, endIRList[i2].X - stIRList[i2].X, endIRList[i2].Y - stIRList[i2].Y),bmp.PixelFormat);

                if (iOld != null)
                {
                    iOld.Dispose();
                    iOld = null;
                }
            }
        }
        pictureBox1.Image =this.videoSourcePlayer.GetCurrent();

        TestPicBox.Image = tempB;


        return tempB;
    }

the problem I am having is at:

tempB = bmp.Clone(new Rectangle(stIRList[i2].X, stIRList[i2].Y, endIRList[i2].X - stIRList[i2].X, endIRList[i2].Y - stIRList[i2].Y),bmp.PixelFormat);

解决方案

I am using videoSourcePlayer from AForge. now I had to add a function to it because GetCurrentVideoFrame( ) was not working the why I needed. So I make a function called GetCurrent() and it work the way I wanted. The problem I am having is when I used it in place of GetCurrentVideoFrame( ) I get a System.OutOfMemoryException: 'Out of memory.' Exception and I have no Ideal why. here is my code :

Bitmap getPic2(int i2)
    {
        Bitmap bmp = null;
        Bitmap tempB = null;
        if (endIRList[i2].X > videoSourcePlayer.Width - 1)
            endIRList[i2]= new System.Drawing.Point(videoSourcePlayer.Width - 1, endIRList[i2].Y);
        if (endIRList[i2].Y > videoSourcePlayer.Height - 1)
            endIRList[i2] = new System.Drawing.Point(endIRList[i2].X, videoSourcePlayer.Height - 1);
        if (stIRList[i2].X >= 0 && stIRList[i2].Y >= 0 && endIRList[i2].X < videoSourcePlayer.Width && endIRList[i2].Y < videoSourcePlayer.Height)
        {
            if (endIRList[i2].X - stIRList[i2].X > 0 && endIRList[i2].Y - stIRList[i2].Y > 0)
            {
                bmp = videoSourcePlayer.GetCurrent();
                System.Drawing.Image iOld = p2.Image;
                tempB = bmp.Clone(new Rectangle(stIRList[i2].X, stIRList[i2].Y, endIRList[i2].X - stIRList[i2].X, endIRList[i2].Y - stIRList[i2].Y),bmp.PixelFormat);

                if (iOld != null)
                {
                    iOld.Dispose();
                    iOld = null;
                }
            }
        }
        pictureBox1.Image =this.videoSourcePlayer.GetCurrent();

        TestPicBox.Image = tempB;


        return tempB;
    }

the problem I am having is at:

tempB = bmp.Clone(new Rectangle(stIRList[i2].X, stIRList[i2].Y, endIRList[i2].X - stIRList[i2].X, endIRList[i2].Y - stIRList[i2].Y),bmp.PixelFormat);

now if I just use bmp = GetCurrentVideoFrame I do not get the problem. so something most be wrong with my function GetCurrentVideo

here is the code :

public Bitmap GetCurrentVideoFrame( )
    {
        lock ( sync )
        {
            return ( currentFrame == null ) ? null : AForge.Imaging.Image.Clone( currentFrame );
        }
    }

    public Bitmap GetCurrent()
    {
        lock (sync)
        {

            Bitmap original = GetCurrentVideoFrame();
            currentPic = new Bitmap(original, new Size(original.Width / 2, original.Height / 2));
            original.Dispose();
            original = null;
            return currentPic;
        }

    }


I just cant see why their function works and my does not. can anyone help?



这篇关于C#System.OutOfMemoryException:'内存不足'。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆