Example of C # image interception

Source: Internet
Author: User
Tags bulk insert

In this paper, the implementation method of C # image interception is described. Share to everyone for your reference. Specific as follows:

The relevant code for image interception is as follows:


The code is as follows:

Public Form1 ()

{

InitializeComponent ();

}

private void Button1_Click (object sender, EventArgs e)

{

Image pic = new Bitmap (this. Width, this. Height);

Graphics graphic = graphics.fromimage (pic);

Graphic. CopyFromScreen (The new point. Location.x, this. LOCATION.Y), new Point (0, 0), new Size (this. Width, this. Height));

pic. Save (@ "D:/test.jpeg", imageformat.jpeg);

Graphic. Dispose ();

}

[System.Runtime.InteropServices.DllImportAttribute ("Gdi32.dll")]

private static extern bool BitBlt (

IntPtr hdcdest,//handle of target device

int nxdest,//x-coordinate of the upper-left corner of the target object

int nydest,//x-coordinate of the upper-left corner of the target object

int nwidth,//width of the rectangle of the target object

int nheight,//length of the rectangle of the target object

IntPtr hdcsrc,//Handle of source device

int NXSRC,//x-coordinate of the upper-left corner of the source object

int NYSRC,//x-coordinate of the upper-left corner of the source object

System.Int32 dwrop//Raster operation values

);

[System.Runtime.InteropServices.DllImportAttribute ("Gdi32.dll")]

private static extern IntPtr CreateDC (

String lpszdriver,//driver name

String lpszdevice,//device name

String lpszoutput,//useless, can be set to locate "NULL"

INTPTR Lpinitdata//Any printer data

);

private void Form1_sizechanged (object sender, EventArgs e)

{

}

private void Button2_Click (object sender, EventArgs e)

{

This. Hide ();

IntPtr DC1 = CreateDC ("DISPLAY", NULL,

NULL, (INTPTR) null);

//Create a DC for the monitor

Graphics g1 = GRAPHICS.FROMHDC (DC1);

//Creates a new graphics object by a handle to a specified device

Bitmap myimage =

New Bitmap (Screen.PrimaryScreen.Bounds.Width,

Screen.PrimaryScreen.Bounds.Height, G1);

//Create a Bitmap object of the same size according to the screen size

Graphics g2 = Graphics.fromimage (myimage);

//Get a handle to the screen

IntPtr DC3 = G1. GetHdc ();

//Get handle to bitmap

IntPtr dc2 = G2. GetHdc ();

//Capture the current screen in the bitmap object

BitBlt (DC2, 0, 0, Screen.PrimaryScreen.Bounds.Width,

Screen.PrimaryScreen.Bounds.Height,

DC3, 0, 0, 13369376);

//Copy the current screen into the bitmap

G1. RELEASEHDC (DC3);

//Release the screen handle

G2. RELEASEHDC (DC2);

//free bitmap handle

Bitmap img = new Bitmap (myimage, 800, 600);

Zoom picture to 800*600

Img. Save ("D:\\myjpeg.jpg", imageformat.jpeg);

MessageBox.Show ("The current screen has been saved to" +

"In the C:\\myjpeg.jpg file! ”);

This. Show ();

}

In addition to the Declaration, Running GuestArticles are original, reproduced please link to the form of the address of this article
Example of C # image interception

This address: http://www.paobuke.com/develop/c-develop/pbk23433.html






Related Content C # generate beautiful verification Code complete code class analysis of type systems (value types and reference types) in C # several databases in C # large data BULK INSERT (SQL Server, Oracle, SQLite, and MySQL) C # Brush pen method for drawing graphics using paths
C # Brush Pen usages Example C # read all specified types of files in a directory The lazy evaluation in C # function programming win7 WinForm programming using SaveFileDialog cannot eject a solution to save a form

Example of C # image interception

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.