Use Aforge.net to do the screen and write each bitmap to the AVI file. Super simple!
Aforge. NET Screencapturestream performance is limited, at present the test basically can reach about 10 frames.
Setting the Aviwriter's framerate to 8 frames, but playing like fast forward, has not yet found the reason. Temporarily take a new frame when it arrives, write a few more ways to circumvent it.
Please contact me if you have any idea how to handle it.
The detailed code is as follows:
Public partial class Form1:form {screen c = screen.primaryscreen; Aviwriter write; <summary>///screenshot instance///</summary> screencapturestream cap; Pen p = new Pen (brushes.red, 5); Pen P2 = new Pen (brushes.green, 5); BOOL Isstart = false; Public Form1 () {InitializeComponent (); } void Cap_newframe (object sender, Newframeeventargs EventArgs) {Debug.WriteLine (DateTime.Now.To String ("Yyyy-mm-dd HH:mm:ss.fff")); int x = control.mouseposition.x; int y = CONTROL.MOUSEPOSITION.Y; using (Graphics g = graphics.fromimage (Eventargs.frame)) {//Draw time g.DrawString (Dat ETime.Now.ToString (), New Font ("Arial", 14f, FontStyle.Bold), brushes.red, New PointF (100, 100)); Picture mouse position G.drawellipse (p, new Rectangle (x-10, y-10, 20, 20)); } if (ContRol. MouseButtons = = MouseButtons.Left) {//left mouse button click, Draw click image Bitmap Bt_re = (Bitmap) even TArgs.Frame.Clone (); using (Graphics g = graphics.fromimage (bt_re)) {G.smoothingmode = Smoothingmode.highspe Ed G.drawellipse (P2, New Rectangle (x-20, y-20, 40, 40)); } write. Addframe (Eventargs.frame); Write. Addframe (bt_re); Write. Addframe (bt_re); Write. Addframe (Eventargs.frame); } else {write. Addframe (Eventargs.frame); }//write more once, if not more write, feel like playing in fast forward. There is no use in setting the frame rate in front. Have a master to know, please answer. Write. Addframe (Eventargs.frame); The private void Form1_Load (object sender, EventArgs e) {button2. Enabled = false; P.startcap = Linecap.round; P.endcap = Linecap.round; P2. StartCap = Linecap.round; P2.EndCap = Linecap.round; } private void Button1_Click (object sender, EventArgs e) {Isstart = true; Cap = new Screencapturestream (c.bounds,125); Cap. Newframe + = new Newframeeventhandler (cap_newframe); String filename=datetime.now.tostring () + "Avi"; SaveFileDialog SF = new SaveFileDialog (); sf. Filter = "video file |*.avi"; if (SF. ShowDialog () = = DialogResult.OK) {filename = sf. FileName; Write = new Aviwriter (); Write. Open (filename, c.bounds.width, c.bounds.height); Write. framerate = 8; Cap. Start (); } button1. Enabled = false; Button2. Enabled = true; } private void Button2_Click (object sender, EventArgs e) {//multi-1s recording screen thread.sle EP (1000); Cap. Stop (); Write. Close (); Write. Dispose (); Button1.Enabled = true; Button2. Enabled = false; } }
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
The C # recording screen is super easy!