How to Grab Predefined Region coordinate value for screenshot? [duplicate]
Possible Duplicate:
.NET Equivalent of Snipping Tool
My code below is taking screenshot for the whole screen, but I would like to take a screenshot with a pre-defined region. I prefer to click on a button then drag and select the region I want to grab x, y, destinationX, destinationY value. Can someone give me a hint or sample how to do that?
bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
Screen.PrimaryScreen.Bounds.Height,
PixelFormat.Format32bppArgb);
// C开发者_如何转开发reate a graphics object from the bitmap
gfxScreenshot = Graphics.FromImage(bmpScreenshot);
// Take the screenshot from the upper left corner to the right bottom corner
gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X,
Screen.PrimaryScreen.Bounds.Y,
0,
0,
Screen.PrimaryScreen.Bounds.Size,
CopyPixelOperation.SourceCopy);
I haven't really done much bitmap/graphics work but can you simply not capture the X,Y co-ordinates of the mouse_down and mouse_up events and then use those in your CopyFromScreen method
Something like:
private void Form1_MouseDown(object sender, MouseEventArgs e)
{
startX = e.X;
startY = e.Y;
}
private void Form1_MouseUp(object sender, MouseEventArgs e)
{
endX = e.X;
endY = e.Y;
}
You can then do a little math to determine the size of the area to transfer and feed that into your method.
精彩评论