AForge.NET

  :: AForge.NET Framework :: Articles :: Forums ::

Bitmap problem with new frame

The forum is to discuss topics related to different areas of image processing and computer vision.

Bitmap problem with new frame

Postby lilmemt » Wed Jan 25, 2012 11:02 am

Hello,

i have a problem with the newframe methods
Code: Select all
public  void FinalVideoSource_NewFrame(object sender, NewFrameEventArgs eventArgs)
        {
            pbxApercu.Image = (Bitmap)eventArgs.Frame.Clone();
            pbxApercu.Image.Dispose();
        }


i have a big red cross on the picture box !! Can someone help me ??

Thanks, LilMemt
User avatar
lilmemt
 
Posts: 20
Joined: Tue Jan 17, 2012 1:25 pm
Location: switzerland

Re: Bitmap problem with new frame

Postby andrew.kirillov » Wed Jan 25, 2012 11:10 am

Hello,

Not surprised it is big and red. What do you expect should be displayed in your picture box? You set a picture to the picture box and immediately dispose it. So the picture box tries to paint that picture, but it is gone - disposed. Of course picture box generates exception, since it cannot access disposed object.
With best regards,
Andrew


Interested in supporting AForge.NET Framework?
User avatar
andrew.kirillov
Site Admin, AForge.NET Developer
 
Posts: 3453
Joined: Fri Jan 23, 2009 9:12 am
Location: UK

Re: Bitmap problem with new frame

Postby lilmemt » Wed Feb 08, 2012 8:27 am

if i don't dispose it the ram memory increases up to 2 gigabytes ! and after that the programm crash !!
User avatar
lilmemt
 
Posts: 20
Joined: Tue Jan 17, 2012 1:25 pm
Location: switzerland

Re: Bitmap problem with new frame

Postby andrew.kirillov » Wed Feb 08, 2012 10:50 am

Sure it will increase, because you do Clone() and don't dispose it :D You need to dispose images, but you don't need to do it right after setting them to PictureBox, which has nothing to display then. Your initial code is just completely wrong.

Here is clue:
Code: Select all
Image oldImage = pbxApercu.Image;
pbxApercu.Image = (Bitmap)eventArgs.Frame.Clone();

if ( oldImage != null )
{
   oldImage .Dispose();
}
With best regards,
Andrew


Interested in supporting AForge.NET Framework?
User avatar
andrew.kirillov
Site Admin, AForge.NET Developer
 
Posts: 3453
Joined: Fri Jan 23, 2009 9:12 am
Location: UK

Re: Bitmap problem with new frame

Postby manu0087 » Mon Oct 23, 2017 7:18 am

hi,
i have similar problem, i tried to dispose my picturbox before to change it and after some seconds i have and unhandles exception like 'invalid parameters'.
Code: Select all
if (pictureBox1.Image != null)
                {
                    pictureBox1.Image.Dispose();
                }

pictureBox1.Image = new Bitmap(eventArgs.Frame, new Size(pictureBox1.Width, pictureBox1.Height));
//pictureBox1.Image = (Bitmap)eventArgs.Frame.Clone();


instead, if i keep original size, all fine...

i tried with delegate and works, but i can t release videosource with Stop().

what i wrong?!

thank you!
manu0087
 
Posts: 1
Joined: Mon Oct 23, 2017 7:05 am




Return to Image Processing and Computer Vision

cron