oops another problem

D

dawn

Hi,

With the code I use to capture part of a form, an error shows up : External
GDI+ error

the code is the following

private void button3_Click(object sender, System.EventArgs e)
{

resdial.Activate() ;

System.IntPtr srcDC=GetDC(resdial.axWebBrowser1.Handle);

Bitmap bm=new Bitmap(50,50);

Graphics g=Graphics.FromImage(bm);

System.IntPtr bmDC=g.GetHdc();


BitBlt(bmDC,0,0,bm.Width,bm.Height,srcDC,0,0,0x00CC0020 /*SRCCOPY*/);

this.pictureBox1.Image = System.Drawing.Image.FromHbitmap(bmDC);


ReleaseDC(srcDC);

g.ReleaseHdc(bmDC);

g.Dispose();



}



The line that gives the error is

this.pictureBox1.Image = System.Drawing.Image.FromHbitmap(bmDC);



What's wrong with this?



Thanks
 
B

Bob Powell [MVP]

Your code attempts to use a grabbed DC in two places.

The code below ought to work (untested)

private void button3_Click(object sender, System.EventArgs e)
{

resdial.Activate() ;

System.IntPtr srcDC=GetDC(resdial.axWebBrowser1.Handle);

Bitmap bm=new Bitmap(50,50);

Graphics g=Graphics.FromImage(bm);

System.IntPtr bmDC=g.GetHdc();


BitBlt(bmDC,0,0,bm.Width,bm.Height,srcDC,0,0,0x00CC0020 /*SRCCOPY*/);


ReleaseDC(srcDC);

g.ReleaseHdc(bmDC);

g.Dispose();

this.pictureBox1.Image=bm;

}


--
Bob Powell [MVP]
C#, System.Drawing

The October edition of Well Formed is now available.
Find out how to use DirectX in a Windows Forms control
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

Read my Blog at http://bobpowelldotnet.blogspot.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top