обновление
Я использую videoSourcePlayer из AForge.теперь я должен был добавить к нему функцию, потому что 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 && 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;
}
проблема, с которой я сталкиваюсь:
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);
сейчас, если я просто использую bmp = GetCurrentVideoFrame
, я не получаю проблему.что-то должно быть не так с моей функцией GetCurrentVideo
вот код:
public Bitmap GetCurrentVideoFrame( )
{
lock ( sync )
{
return ( currentFrame == null ) ? null : AForge.Imaging.Image.Clone( currentFrame );
}
}
public Bitmap GetCurrent()
{
lock (sync)
{
Bitmap currentPic = null;
Bitmap original = GetCurrentVideoFrame();
currentPic = new Bitmap(original, new Size(original.Width / 2, original.Height / 2));
original.Dispose();
original = null;
return currentPic;
}
}
Я просто не могу понять, почему их функция работает, а моя - нет.кто-нибудь может помочь?