Graphics.CopyFromScreen Méthode

Définition

Effectue le transfert de bloc de bits des données de couleur de l'écran à la surface de dessin de Graphics.

Surcharges

CopyFromScreen(Point, Point, Size)

Effectue le transfert de bloc de bits des données de couleur correspondant à un rectangle de pixels de l'écran à la surface de dessin de Graphics.

CopyFromScreen(Point, Point, Size, CopyPixelOperation)

Effectue le transfert de bloc de bits des données de couleur correspondant à un rectangle de pixels de l'écran à la surface de dessin de Graphics.

CopyFromScreen(Int32, Int32, Int32, Int32, Size)

Effectue le transfert de bloc de bits des données de couleur correspondant à un rectangle de pixels de l'écran à la surface de dessin de Graphics.

CopyFromScreen(Int32, Int32, Int32, Int32, Size, CopyPixelOperation)

Effectue le transfert de bloc de bits des données de couleur correspondant à un rectangle de pixels de l'écran à la surface de dessin de Graphics.

CopyFromScreen(Point, Point, Size)

Effectue le transfert de bloc de bits des données de couleur correspondant à un rectangle de pixels de l'écran à la surface de dessin de Graphics.

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)

Paramètres

upperLeftSource
Point

Point situé dans l'angle supérieur gauche du rectangle source.

upperLeftDestination
Point

Point situé dans l'angle supérieur gauche du rectangle de destination.

blockRegionSize
Size

Taille de la zone à transférer.

Exceptions

L'opération a échoué.

Exemples

L'exemple suivant décrit comment utiliser la méthode CopyFromScreen. Pour exécuter cet exemple, collez-le dans un Windows Form. Gérez l’événement du Paint formulaire et appelez la CopyPixels1 méthode à partir de la Paint méthode de gestion des événements, en passant comme ePaintEventArgs.

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

Remarques

Les CopyFromScreen méthodes sont utiles pour superposer une image sur une autre. Pour spécifier la façon dont les couleurs source et destination sont fusionnées, utilisez l’une CopyFromScreen des méthodes qui prend un CopyPixelOperation paramètre.

Voir aussi

S’applique à

CopyFromScreen(Point, Point, Size, CopyPixelOperation)

Effectue le transfert de bloc de bits des données de couleur correspondant à un rectangle de pixels de l'écran à la surface de dessin de Graphics.

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)

Paramètres

upperLeftSource
Point

Point situé dans l'angle supérieur gauche du rectangle source.

upperLeftDestination
Point

Point situé dans l'angle supérieur gauche du rectangle de destination.

blockRegionSize
Size

Taille de la zone à transférer.

copyPixelOperation
CopyPixelOperation

Une des valeurs de l'objet CopyPixelOperation.

Exceptions

copyPixelOperation n’est pas membre de CopyPixelOperation

L'opération a échoué.

Exemples

L'exemple suivant décrit comment utiliser la méthode CopyFromScreen. Pour exécuter cet exemple, collez-le dans un Windows Form. Gérez l’événement du Paint formulaire et appelez la CopyPixels2 méthode à partir de la Paint méthode de gestion des événements, en passant comme ePaintEventArgs.

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

Remarques

Les CopyFromScreen méthodes sont utiles pour superposer une image sur une autre. Le copyPixelOperation paramètre vous permet de spécifier si et comment les couleurs sources doivent être fusionnées avec les couleurs de la zone de destination.

Voir aussi

S’applique à

CopyFromScreen(Int32, Int32, Int32, Int32, Size)

Effectue le transfert de bloc de bits des données de couleur correspondant à un rectangle de pixels de l'écran à la surface de dessin de Graphics.

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)

Paramètres

sourceX
Int32

Coordonnée x du point situé dans l'angle supérieur gauche du rectangle source.

sourceY
Int32

Coordonnée y du point situé dans l'angle supérieur gauche du rectangle source.

destinationX
Int32

Coordonnée x du point situé dans l'angle supérieur gauche du rectangle de destination.

destinationY
Int32

Coordonnée y du point situé dans l'angle supérieur gauche du rectangle de destination.

blockRegionSize
Size

Taille de la zone à transférer.

Exceptions

L'opération a échoué.

Exemples

L’exemple de code suivant montre comment utiliser pour CopyFromScreen imprimer une copie du formulaire actif.

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

Remarques

Les CopyFromScreen méthodes sont utiles pour superposer une image sur une autre. Pour spécifier la façon dont les couleurs source et destination sont fusionnées, utilisez l’une CopyFromScreen des méthodes qui prend un CopyPixelOperation paramètre.

Voir aussi

S’applique à

CopyFromScreen(Int32, Int32, Int32, Int32, Size, CopyPixelOperation)

Effectue le transfert de bloc de bits des données de couleur correspondant à un rectangle de pixels de l'écran à la surface de dessin de Graphics.

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)

Paramètres

sourceX
Int32

Coordonnée x du point situé dans l'angle supérieur gauche du rectangle source.

sourceY
Int32

Coordonnée y du point situé dans l'angle supérieur gauche du rectangle source.

destinationX
Int32

Coordonnée x du point situé dans l'angle supérieur gauche du rectangle de destination.

destinationY
Int32

Coordonnée y du point situé dans l'angle supérieur gauche du rectangle de destination.

blockRegionSize
Size

Taille de la zone à transférer.

copyPixelOperation
CopyPixelOperation

Une des valeurs de l'objet CopyPixelOperation.

Exceptions

copyPixelOperation n’est pas membre de CopyPixelOperation

L'opération a échoué.

Exemples

L'exemple suivant décrit comment utiliser la méthode CopyFromScreen. Pour exécuter cet exemple, collez-le dans un Windows Form. Gérez l’événement du Paint formulaire et appelez la CopyPixels4 méthode à partir de la Paint méthode de gestion des événements, en passant comme ePaintEventArgs.

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

Remarques

Les CopyFromScreen méthodes sont utiles pour superposer une image sur une autre. Le copyPixelOperation paramètre vous permet de spécifier si et comment les couleurs sources doivent être fusionnées avec les couleurs de la zone de destination.

Voir aussi

S’applique à