Bitmap clone out of memory

  • Thread starter Thread starter Btb4198
  • Start date Start date
B

Btb4198

Guest
I can draw a blue box around an area on my video player and clone that part of the picture. however, it seems that if I get to close to the end of the picture I get an out of memory exception. However, I am not that close to the edges, and over all, I should never be getting that exception, because I am drawing inside the video player...

here is my code:

// alignment camera's dimensions with the video player
private Bitmap alignment()
{
// making a new Bitmap using the video player's dimensions
Bitmap tempBitmap = new Bitmap(videoSourcePlayer.Width, videoSourcePlayer.Height);
// making a new Graphic from that bitmap
Graphics g = Graphics.FromImage(tempBitmap);
// getting picture from the camera
Bitmap originalBmp = videoSourcePlayer.GetCurrentVideoFrame();
while (originalBmp == null)
{
originalBmp = videoSourcePlayer.GetCurrentVideoFrame();
}
//making new bitmap using the Graphics g
g.DrawImage(originalBmp, 0, 0, videoSourcePlayer.Width, videoSourcePlayer.Height);
// returning the new bitmap
return tempBitmap;
}



Bitmap getPic2() // I removed the int i2, you did not need it at a parameter, you did not need it
{
Bitmap bmp = null;
Bitmap tempB = null;

// getting the current image from the video player
bmp = alignment();//videoSourcePlayer.GetCurrentVideoFrame();
// if somehow the box is bigger than the video Source Player control than just used the
// videoSourcePlayer Width and hight
if (_endIR.X > videoSourcePlayer.Width - 1)
_endIR = new System.Drawing.Point(videoSourcePlayer.Width - 1, _endIR.Y);
if (_endIR.Y > videoSourcePlayer.Height - 1)
_endIR = new System.Drawing.Point(_endIR.X, videoSourcePlayer.Height - 1);
if (_stIR2.X >= 0 && _stIR2.Y >= 0 && _endIR.X < videoSourcePlayer.Width && _endIR.Y < videoSourcePlayer.Height)
{
//if (_endIR.X - _stIR2.X >= 0 && _endIR.Y - _stIR2.Y >= 0)
//{
//Taking the dimensions from the box and using that to cut out a new image from the current video stream
int recW = Math.Abs( _endIR.X - _stIR2.X);
int recH = Math.Abs(_endIR.Y - _stIR2.Y);
tempB = bmp.Clone(new Rectangle(_stIR2.X, _stIR2.Y, recW, recH), bmp.PixelFormat);

if (bmp != null)
{
// free up the memory
bmp.Dispose();
bmp = null;
}
//}
}

return tempB;
}





his exception at all.

here is my code :

Continue reading...
 
Back
Top