C # image capture demo

Source: Internet
Author: User
Demo

Using system; using system. collections. generic; using system. componentmodel; using system. data; using system. drawing; using system. text; using system. windows. forms; using system. drawing. imaging; namespace image {public partial class form1: FORM {bool isdrag = false; rectangle therectangle = new rectangle (new point (0, 0), new size (0, 0 )); point startpoint, oldpoint; private graphics ig; Public form1 () {init Ializecomponent ();} private void button1_click (Object sender, eventargs e) {} private void button2_click (Object sender, eventargs e) {openfiledialog1.filter = "*. JPG ,*. JPEG ,*. BMP ,*. GIF ,*. ICO ,*. PNG ,*. TIF ,*. WMF | *. JPG ;*. JPEG ;*. BMP ;*. GIF ;*. ICO ;*. PNG ;*. TIF ;*. WMF "; openfiledialog1.showdialog (); image myimage = system. drawing. image. fromfile (openfiledialog1.filename); picturebox1.image = myimage;} PRI Vate void picturebox#mousedown (Object sender, mouseeventargs e) {If (E. Button = mousebuttons. Left) {// If painting starts, record the mouse position if (isdrag =! Isdrag) = true) {startpoint = new point (e. x, E. y); oldpoint = new point (e. x, E. y) ;}} private void picturebox#mouseup (Object sender, mouseeventargs e) {isdrag = false; ig = picturebox1.creategraphics (); Ig. drawrectangle (new pen (color. black, 1), startpoint. x, startpoint. y, E. x-startpoint. x, E. y-startpoint. y); therectangle = new rectangle (startpoint. x, startpoint. y, E. x-startpoint. x, E. y-startpoint. y);} private void picturebox#mouseclick (Object sender, mouseeventargs e) {try {// graphics = This. creategraphics (); Bitmap bitmap = new Bitmap (picturebox1.image); bitmap clonebitmap = bitmap. clone (therectangle, pixelformat. dontcare); picturebox2.image = (image) clonebitmap; // graphics. drawimage (clonebitmap, E. x, E. y); graphics G = picturebox1.creategraphics (); solidbrush mybrush = new solidbrush (color. transparent); G. fillrectangle (mybrush, therectangle);} catch {}}}}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.