For several days, the object is more, the mess is messy, and finally a try out.
Bitmap
Graphics
FromImage
Pen
Rectangle
DrawRectangle
Really confused, looked for several days, only to understand the relationship between the parameters.
Download Pan.baidu.com/s/1c2cmrhy
Idea: Form1 is the interface, full screen. Form2 on the area
Form1 Code
inti =0; intW =Screen.PrimaryScreen.Bounds.Width; inth =Screen.PrimaryScreen.Bounds.Height; Private voidButton1_Click (Objectsender, EventArgs e) {WindowState=formwindowstate.minimized; Thread.Sleep ( -); I+=1; Bitmap b=NewBitmap (W,H); Graphics g=Graphics.fromimage (b); G.copyfromscreen (0,0,0,0,NewSize (w,h)); B.save ("c:/users/administrator/desktop/Little Prince"+i+". jpg"); WindowState=Formwindowstate.normal; Clipboard.setimage (b); This. Cursor =Cursors.Default; } Private voidButton3_Click (Objectsender, EventArgs e) {System.Diagnostics.Process.Start ("C:/users/administrator/desktop"); Topmost=false; This. Cursor =Cursors.Default; } Private voidButton2_Click (Objectsender, EventArgs e) { This. Hide (); Form2 F2=NewForm2 (); F2. Show (); }
Form2 Code
inti =0; Bitmap bit; Bitmap Bit2; Bitmap copy; intx; inty; intxx; intyy; Pen Pen=NewPen (Color.Red,2); Rectangle rect=NewRectangle (); Graphics G2; Private voidForm2_load (Objectsender, EventArgs e) {i++; //Opacity = 0.5;WindowState =formwindowstate.minimized; FormBorderStyle=Formborderstyle.none; This. Cursor =Cursors.cross; intW =Screen.PrimaryScreen.Bounds.Width; inth =Screen.PrimaryScreen.Bounds.Height; Bit=NewBitmap (W, h);//Get desktop DiagramGraphics g = graphics.fromimage (bit);//get the picture out.G.copyfromscreen (0,0,0,0,NewSize (W, h)); pictureBox1.Image=bit; Bit. Save ("c:/users/administrator/desktop/Area"+ i +". jpg"); WindowState=formwindowstate.maximized; } Private voidPicturebox1_mouseclick (Objectsender, MouseEventArgs e) { if(E.button = =mousebuttons.right) { This. Hide (); Form1 F1=NewForm1 (); F1. Show (); } } Private voidPicturebox1_mousedown (Objectsender, MouseEventArgs e) {x=Math.Abs (e.x); Y=Math.Abs (E.Y); } Private voidPicturebox1_mousemove (Objectsender, MouseEventArgs e) { if(E.button = =mousebuttons.left) {xx=Math.Abs (e.x); YY=Math.Abs (E.Y); Graphics g=Picturebox1.creategraphics (); Rect=NewRectangle (x, y, Xx-x, yy-y); Refresh (); G.drawrectangle (pen, rect); } } Private voidPicturebox1_mouseup (Objectsender, MouseEventArgs e) { Try{Copy=(Bitmap) bit. Clone (); Bit2=NewBitmap (rect. Width, Rect. Height); G2=graphics.fromimage (BIT2); G2. DrawImage (Copy,NewRectangle (0,0, Rect. Width, Rect. Height), rect, graphicsunit.pixel); pictureBox1.Image=Bit2; Bit2. Save ("c:/users/administrator/desktop/Area"+ i +". jpg"); Clipboard.setimage (BIT2); }
C # Tools WinForm