Graphics.CopyFromScreen 方法
定义
重载
CopyFromScreen(Int32, Int32, Int32, Int32, Size) |
执行颜色数据(对应于由像素组成的矩形)从屏幕到 Graphics 的绘图图面的位块传输。Performs a bit-block transfer of the color data, corresponding to a rectangle of pixels, from the screen to the drawing surface of the Graphics. |
CopyFromScreen(Int32, Int32, Int32, Int32, Size, CopyPixelOperation) |
执行颜色数据(对应于由像素组成的矩形)从屏幕到 Graphics 的绘图图面的位块传输。Performs a bit-block transfer of the color data, corresponding to a rectangle of pixels, from the screen to the drawing surface of the Graphics. |
CopyFromScreen(Point, Point, Size) |
执行颜色数据(对应于由像素组成的矩形)从屏幕到 Graphics 的绘图图面的位块传输。Performs a bit-block transfer of color data, corresponding to a rectangle of pixels, from the screen to the drawing surface of the Graphics. |
CopyFromScreen(Point, Point, Size, CopyPixelOperation) |
执行颜色数据(对应于由像素组成的矩形)从屏幕到 Graphics 的绘图图面的位块传输。Performs a bit-block transfer of color data, corresponding to a rectangle of pixels, from the screen to the drawing surface of the Graphics. |
CopyFromScreen(Int32, Int32, Int32, Int32, Size)
public:
void CopyFromScreen(int sourceX, int sourceY, int destinationX, int destinationY, System::Drawing::Size blockRegionSize);
public void CopyFromScreen (int sourceX, int sourceY, int destinationX, int destinationY, System.Drawing.Size blockRegionSize);
member this.CopyFromScreen : int * int * int * int * System.Drawing.Size -> unit
Public Sub CopyFromScreen (sourceX As Integer, sourceY As Integer, destinationX As Integer, destinationY As Integer, blockRegionSize As Size)
参数
- sourceX
- Int32
位于源矩形左上角的点的 x 坐标。The x-coordinate of the point at the upper-left corner of the source rectangle.
- sourceY
- Int32
位于源矩形左上角的点的 y 坐标。The y-coordinate of the point at the upper-left corner of the source rectangle.
- destinationX
- Int32
位于目标矩形左上角的点的 x 坐标。The x-coordinate of the point at the upper-left corner of the destination rectangle.
- destinationY
- Int32
位于目标矩形左上角的点的 y 坐标。The y-coordinate of the point at the upper-left corner of the destination rectangle.
- blockRegionSize
- Size
要传输的区域大小。The size of the area to be transferred.
例外
此操作失败。The operation failed.
示例
下面的代码示例演示如何使用 CopyFromScreen 来打印当前窗体的副本。The following code example demonstrates how to use the CopyFromScreen for printing a copy of the current form.
using System;
using System.Windows.Forms;
using System.Drawing;
using System.Drawing.Printing;
public class Form1 :
Form
{
private Button printButton = new Button();
private PrintDocument printDocument1 = new PrintDocument();
public Form1()
{
printButton.Text = "Print Form";
printButton.Click += new EventHandler(printButton_Click);
printDocument1.PrintPage += new PrintPageEventHandler(printDocument1_PrintPage);
this.Controls.Add(printButton);
}
void printButton_Click(object sender, EventArgs e)
{
CaptureScreen();
printDocument1.Print();
}
Bitmap memoryImage;
private void CaptureScreen()
{
Graphics myGraphics = this.CreateGraphics();
Size s = this.Size;
memoryImage = new Bitmap(s.Width, s.Height, myGraphics);
Graphics memoryGraphics = Graphics.FromImage(memoryImage);
memoryGraphics.CopyFromScreen(this.Location.X, this.Location.Y, 0, 0, s);
}
private void printDocument1_PrintPage(System.Object sender,
System.Drawing.Printing.PrintPageEventArgs e)
{
e.Graphics.DrawImage(memoryImage, 0, 0);
}
public static void Main()
{
Application.Run(new Form1());
}
}
Imports System.Windows.Forms
Imports System.Drawing
Imports System.Drawing.Printing
Public Class Form1
Inherits Form
Private WithEvents printButton As New Button
Private WithEvents printDocument1 As New PrintDocument
Public Sub New()
printButton.Text = "Print Form"
Me.Controls.Add(printButton)
End Sub
Dim memoryImage As Bitmap
Private Sub CaptureScreen()
Dim myGraphics As Graphics = Me.CreateGraphics()
Dim s As Size = Me.Size
memoryImage = New Bitmap(s.Width, s.Height, myGraphics)
Dim memoryGraphics As Graphics = Graphics.FromImage(memoryImage)
memoryGraphics.CopyFromScreen(Me.Location.X, Me.Location.Y, 0, 0, s)
End Sub
Private Sub printDocument1_PrintPage(ByVal sender As System.Object, _
ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles _
printDocument1.PrintPage
e.Graphics.DrawImage(memoryImage, 0, 0)
End Sub
Private Sub printButton_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles printButton.Click
CaptureScreen()
printDocument1.Print()
End Sub
Public Shared Sub Main()
Application.Run(New Form1())
End Sub
End Class
注解
这些 CopyFromScreen 方法可用于将一个图像层叠到另一个图像之上。The CopyFromScreen methods are useful for layering one image on top of another. 若要指定如何混合源颜色和目标颜色,请使用 CopyFromScreen 采用参数的方法之一 CopyPixelOperation 。To specify how the source and destination colors are blended, use one of the CopyFromScreen methods that takes a CopyPixelOperation parameter.
另请参阅
- 如何:打印 Windows 窗体How to: Print a Windows Form
- 如何:在 Windows 窗体中复制像素以减少闪烁How to: Copy Pixels For Reducing Flicker in Windows Forms
适用于
CopyFromScreen(Int32, Int32, Int32, Int32, Size, CopyPixelOperation)
public:
void CopyFromScreen(int sourceX, int sourceY, int destinationX, int destinationY, System::Drawing::Size blockRegionSize, System::Drawing::CopyPixelOperation copyPixelOperation);
public void CopyFromScreen (int sourceX, int sourceY, int destinationX, int destinationY, System.Drawing.Size blockRegionSize, System.Drawing.CopyPixelOperation copyPixelOperation);
member this.CopyFromScreen : int * int * int * int * System.Drawing.Size * System.Drawing.CopyPixelOperation -> unit
Public Sub CopyFromScreen (sourceX As Integer, sourceY As Integer, destinationX As Integer, destinationY As Integer, blockRegionSize As Size, copyPixelOperation As CopyPixelOperation)
参数
- sourceX
- Int32
位于源矩形左上角的点的 x 坐标。The x-coordinate of the point at the upper-left corner of the source rectangle.
- sourceY
- Int32
位于源矩形左上角的点的 y 坐标The y-coordinate of the point at the upper-left corner of the source rectangle
- destinationX
- Int32
位于目标矩形左上角的点的 x 坐标。The x-coordinate of the point at the upper-left corner of the destination rectangle.
- destinationY
- Int32
位于目标矩形左上角的点的 y 坐标。The y-coordinate of the point at the upper-left corner of the destination rectangle.
- blockRegionSize
- Size
要传输的区域大小。The size of the area to be transferred.
- copyPixelOperation
- CopyPixelOperation
CopyPixelOperation 值之一。One of the CopyPixelOperation values.
例外
copyPixelOperation
不是 CopyPixelOperation 的成员。copyPixelOperation
is not a member of CopyPixelOperation.
此操作失败。The operation failed.
示例
下面的示例演示如何使用 CopyFromScreen 方法。The following example demonstrates how to use the CopyFromScreen method. 若要运行此示例,请将其粘贴到 Windows 窗体中。To run this example, paste it into a Windows Form. 处理窗体的 Paint 事件,并 CopyPixels4
从 Paint 事件处理方法调用方法,并将 e
作为传递 PaintEventArgs 。Handle the form's Paint event and call the CopyPixels4
method from the Paint event-handling method, passing e
as PaintEventArgs.
private void CopyPixels4(PaintEventArgs e)
{
e.Graphics.CopyFromScreen(0, 0, 20, 20, new Size(160, 160),
CopyPixelOperation.SourceInvert);
}
Private Sub CopyPixels4(ByVal e As PaintEventArgs)
e.Graphics.CopyFromScreen(0, 0, 20, 20, _
New Size(160, 160), CopyPixelOperation.SourceInvert)
End Sub
注解
这些 CopyFromScreen 方法可用于将一个图像层叠到另一个图像之上。The CopyFromScreen methods are useful for layering one image on top of another. copyPixelOperation
参数用于指定是否以及如何将源颜色与目标区域中的颜色混合。The copyPixelOperation
parameter allows you to specify if and how the source colors should be blended with the colors in the destination area.
另请参阅
- 如何:打印 Windows 窗体How to: Print a Windows Form
- 如何:在 Windows 窗体中复制像素以减少闪烁How to: Copy Pixels For Reducing Flicker in Windows Forms
适用于
CopyFromScreen(Point, Point, Size)
public:
void CopyFromScreen(System::Drawing::Point upperLeftSource, System::Drawing::Point upperLeftDestination, System::Drawing::Size blockRegionSize);
public void CopyFromScreen (System.Drawing.Point upperLeftSource, System.Drawing.Point upperLeftDestination, System.Drawing.Size blockRegionSize);
member this.CopyFromScreen : System.Drawing.Point * System.Drawing.Point * System.Drawing.Size -> unit
Public Sub CopyFromScreen (upperLeftSource As Point, upperLeftDestination As Point, blockRegionSize As Size)
参数
- upperLeftSource
- Point
位于源矩形左上角的点。The point at the upper-left corner of the source rectangle.
- upperLeftDestination
- Point
位于目标矩形左上角的点。The point at the upper-left corner of the destination rectangle.
- blockRegionSize
- Size
要传输的区域大小。The size of the area to be transferred.
例外
此操作失败。The operation failed.
示例
下面的示例演示如何使用 CopyFromScreen 方法。The following example demonstrates how to use the CopyFromScreen method. 若要运行此示例,请将其粘贴到 Windows 窗体中。To run this example, paste it into a Windows Form. 处理窗体的 Paint 事件,并 CopyPixels1
从 Paint 事件处理方法调用方法,并将 e
作为传递 PaintEventArgs 。Handle the form's Paint event and call the CopyPixels1
method from the Paint event-handling method, passing e
as PaintEventArgs.
private void CopyPixels1(PaintEventArgs e)
{
e.Graphics.CopyFromScreen(this.Location,
new Point(40, 40), new Size(100, 100));
}
Private Sub CopyPixels1(ByVal e As PaintEventArgs)
e.Graphics.CopyFromScreen(Me.Location, _
New Point(40, 40), New Size(100, 100))
End Sub
注解
这些 CopyFromScreen 方法可用于将一个图像层叠到另一个图像之上。The CopyFromScreen methods are useful for layering one image on top of another. 若要指定如何混合源颜色和目标颜色,请使用 CopyFromScreen 采用参数的方法之一 CopyPixelOperation 。To specify how the source and destination colors are blended, use one of the CopyFromScreen methods that takes a CopyPixelOperation parameter.
另请参阅
- 如何:打印 Windows 窗体How to: Print a Windows Form
- 如何:在 Windows 窗体中复制像素以减少闪烁How to: Copy Pixels For Reducing Flicker in Windows Forms
适用于
CopyFromScreen(Point, Point, Size, CopyPixelOperation)
public:
void CopyFromScreen(System::Drawing::Point upperLeftSource, System::Drawing::Point upperLeftDestination, System::Drawing::Size blockRegionSize, System::Drawing::CopyPixelOperation copyPixelOperation);
public void CopyFromScreen (System.Drawing.Point upperLeftSource, System.Drawing.Point upperLeftDestination, System.Drawing.Size blockRegionSize, System.Drawing.CopyPixelOperation copyPixelOperation);
member this.CopyFromScreen : System.Drawing.Point * System.Drawing.Point * System.Drawing.Size * System.Drawing.CopyPixelOperation -> unit
Public Sub CopyFromScreen (upperLeftSource As Point, upperLeftDestination As Point, blockRegionSize As Size, copyPixelOperation As CopyPixelOperation)
参数
- upperLeftSource
- Point
位于源矩形左上角的点。The point at the upper-left corner of the source rectangle.
- upperLeftDestination
- Point
位于目标矩形左上角的点。The point at the upper-left corner of the destination rectangle.
- blockRegionSize
- Size
要传输的区域大小。The size of the area to be transferred.
- copyPixelOperation
- CopyPixelOperation
CopyPixelOperation 值之一。One of the CopyPixelOperation values.
例外
copyPixelOperation
不是 CopyPixelOperation 的成员。copyPixelOperation
is not a member of CopyPixelOperation.
此操作失败。The operation failed.
示例
下面的示例演示如何使用 CopyFromScreen 方法。The following example demonstrates how to use the CopyFromScreen method. 若要运行此示例,请将其粘贴到 Windows 窗体中。To run this example, paste it into a Windows Form. 处理窗体的 Paint 事件,并 CopyPixels2
从 Paint 事件处理方法调用方法,并将 e
作为传递 PaintEventArgs 。Handle the form's Paint event and call the CopyPixels2
method from the Paint event-handling method, passing e
as PaintEventArgs.
private void CopyPixels2(PaintEventArgs e)
{
e.Graphics.CopyFromScreen(this.Location, new Point(40, 40),
new Size(100, 100), CopyPixelOperation.MergePaint);
}
Private Sub CopyPixels2(ByVal e As PaintEventArgs)
e.Graphics.CopyFromScreen(Me.Location, _
New Point(40, 40), New Size(100, 100), _
CopyPixelOperation.MergePaint)
End Sub
注解
这些 CopyFromScreen 方法可用于将一个图像层叠到另一个图像之上。The CopyFromScreen methods are useful for layering one image on top of another. copyPixelOperation
参数用于指定是否以及如何将源颜色与目标区域中的颜色混合。The copyPixelOperation
parameter allows you to specify if and how the source colors should be blended with the colors in the destination area.
另请参阅
- 如何:打印 Windows 窗体How to: Print a Windows Form
- 如何:在 Windows 窗体中复制像素以减少闪烁How to: Copy Pixels For Reducing Flicker in Windows Forms