tags:

views:

23

answers:

1

i have this code

Bitmap bmp1, bmp2, bmp3,bmp4;

        Graphics gp2,gp3;



if (bmp2 == null)
                {
                    bmp2 = new Bitmap(pictureBox1.Height, pictureBox1.Width); 
                }
                    gp2 = Graphics.FromImage(bmp2);

                   // Rectangle rect = new Rectangle((float)(pictureBox1.Width / 2),(float)(pictureBox1.Height / 2),width, height);
                    gp2.DrawImageUnscaled(bmp1,0,0);
                    gp2.FillEllipse(Brushes.Red, (float)(pictureBox1.Width / 2), (float)(pictureBox1.Height / 2), width, height);


                    gp2.Dispose();

but i am unable to release the control of gp2 as i want to give its control to gp3;

help required???

A: 

I think you should just be able to dispose of the Graphics and then call Graphics.FromImage again. I don't believe disposing of the Graphics will dispose of the underlying Bitmap. Have you tried it?

Jon Skeet
it works partially some times it generates exception
moon
@moon: What exception? Is it reproducible? Can you provide a short but complete program which demonstrates the problem?
Jon Skeet
it throws exception here in Application.Run(new Form1()); that is Object is currently in use elsewhere.
moon
@moon: No more stack trace than that? Hmm... as before, a short but complete program would really help here...
Jon Skeet