开发者

C# - take picture from inside of a form

OK, I know how DrawToBitmap works or the CopyToScreen methods and all. What I'm looking for is how to take a picture from inside a form (without the form borders, title and maximize box and all) I tried different things for the Rectangle parameter of the DrawToBitmap method but none worked and I just c开发者_如何学Can't figure it out. I appreciate any help.


Well, you have two choices:
1) Go into complex Windows API's
2) Take a screenshot and simply cropping out the form.
1 is probably faster and will work even if something is hiding the form (e.g an other form)
2 will only work if there's nothing hiding the form, and its in the screen.
Well, you can use this code if you like:

Rectangle form = this.Bounds; 
using (Bitmap bitmap = new Bitmap(form.Width, form.Height)) 
{ 
    using (Graphics graphic = 
        Graphics.FromImage(bitmap)) 
    { 
        graphic.CopyFromScreen(form.Location, 
            Point.Empty, form.Size); 
    } 
    bitmap.Save("D://test.jpg", ImageFormat.Jpeg); 
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜