Graphics.CopyFromScreenとは? わかりやすく解説

Graphics.CopyFromScreen メソッド (Point, Point, Size)

メモ : このメソッドは、.NET Framework version 2.0 で新しく追加されたものです。

画面から Graphics の描画サーフェイスへの、ピクセルの四角形に対応する色データのビット ブロック転送を実行します。

名前空間: System.Drawing
アセンブリ: System.Drawing (system.drawing.dll 内)
構文構文

Public Sub CopyFromScreen ( _
    upperLeftSource As Point, _
    upperLeftDestination As Point, _
    blockRegionSize As Size _
)
Dim instance As Graphics
Dim upperLeftSource As Point
Dim upperLeftDestination As Point
Dim blockRegionSize As Size

instance.CopyFromScreen(upperLeftSource, upperLeftDestination, blockRegionSize)
public void CopyFromScreen (
    Point upperLeftSource,
    Point upperLeftDestination,
    Size blockRegionSize
)
public:
void CopyFromScreen (
    Point upperLeftSource, 
    Point upperLeftDestination, 
    Size blockRegionSize
)
public void CopyFromScreen (
    Point upperLeftSource, 
    Point upperLeftDestination, 
    Size blockRegionSize
)
public function CopyFromScreen (
    upperLeftSource : Point, 
    upperLeftDestination : Point, 
    blockRegionSize : Size
)

パラメータ

upperLeftSource

転送元の四角形の左上隅の点。

upperLeftDestination

転送先の四角形の左上隅の点。

blockRegionSize

転送される領域のサイズ。

例外例外
解説解説

CopyFromScreen メソッドは、イメージを重ね合わせてレイアウトする場合に便利です。転送元と転送先の色のブレンド方法を指定するには、CopyPixelOperation パラメータを受け取るいずれかの CopyFromScreen メソッドを使用します。

使用例使用例

CopyFromScreen メソッドを使用する方法の例を次に示します。この例を実行するには、コードを Windows フォームに貼り付けます。フォームの Paint イベントを処理し、e を PaintEventArgs として渡して、Paint イベント処理メソッドから CopyPixels1 メソッドを呼び出します。

Private Sub CopyPixels1(ByVal
 e As PaintEventArgs) 
    e.Graphics.CopyFromScreen(Me.Location, _
        New Point(40, 40), New Size(100, 100))

End Sub
private void CopyPixels1(PaintEventArgs e)
{
    e.Graphics.CopyFromScreen(this.Location, 
        new Point(40, 40), new Size(100, 100));
}
.NET Framework のセキュリティ.NET Framework のセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Graphics.CopyFromScreen メソッド (Int32, Int32, Int32, Int32, Size, CopyPixelOperation)

メモ : このメソッドは、.NET Framework version 2.0 で新しく追加されたものです。

画面から Graphics の描画サーフェイスへの、ピクセルの四角形に対応する色データのビット ブロック転送を実行します。

名前空間: System.Drawing
アセンブリ: System.Drawing (system.drawing.dll 内)
構文構文

Public Sub CopyFromScreen ( _
    sourceX As Integer, _
    sourceY As Integer, _
    destinationX As Integer, _
    destinationY As Integer, _
    blockRegionSize As Size, _
    copyPixelOperation As CopyPixelOperation _
)
Dim instance As Graphics
Dim sourceX As Integer
Dim sourceY As Integer
Dim destinationX As Integer
Dim destinationY As Integer
Dim blockRegionSize As Size
Dim copyPixelOperation As CopyPixelOperation

instance.CopyFromScreen(sourceX, sourceY, destinationX, destinationY, blockRegionSize,
 copyPixelOperation)
public void CopyFromScreen (
    int sourceX,
    int sourceY,
    int destinationX,
    int destinationY,
    Size blockRegionSize,
    CopyPixelOperation copyPixelOperation
)
public:
void CopyFromScreen (
    int sourceX, 
    int sourceY, 
    int destinationX, 
    int destinationY, 
    Size blockRegionSize, 
    CopyPixelOperation copyPixelOperation
)
public void CopyFromScreen (
    int sourceX, 
    int sourceY, 
    int destinationX, 
    int destinationY, 
    Size blockRegionSize, 
    CopyPixelOperation copyPixelOperation
)
public function CopyFromScreen (
    sourceX : int, 
    sourceY : int, 
    destinationX : int, 
    destinationY : int, 
    blockRegionSize : Size, 
    copyPixelOperation : CopyPixelOperation
)

パラメータ

sourceX

転送元の四角形の左上隅の点の x 座標。

sourceY

転送元の四角形の左上隅の点の y 座標。

destinationX

転送先の四角形の左上隅の点の x 座標。

destinationY

転送先の四角形の左上隅の点の y 座標。

blockRegionSize

転送される領域のサイズ。

copyPixelOperation

CopyPixelOperation 値の 1 つ。

例外例外
例外の種類条件

InvalidEnumArgumentException

copyPixelOperation が CopyPixelOperation のメンバではありません。

Win32Exception

操作に失敗しました。

解説解説
使用例使用例

CopyFromScreen メソッドを使用する方法の例を次に示します。この例を実行するには、コードを Windows フォームに貼り付けます。フォームの Paint イベントを処理し、e を PaintEventArgs として渡して、Paint イベント処理メソッドから CopyPixels4 メソッドを呼び出します。

Private Sub CopyPixels4(ByVal
 e As PaintEventArgs) 
    e.Graphics.CopyFromScreen(0, 0, 20, 20, _
        New Size(160, 160), CopyPixelOperation.SourceInvert)
End Sub
private void CopyPixels4(PaintEventArgs e)
{
    e.Graphics.CopyFromScreen(0, 0, 20, 20, new Size(160, 160),
 
        CopyPixelOperation.SourceInvert);
}
.NET Framework のセキュリティ.NET Framework のセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Graphics.CopyFromScreen メソッド (Int32, Int32, Int32, Int32, Size)

メモ : このメソッドは、.NET Framework version 2.0 で新しく追加されたものです。

画面から Graphics の描画サーフェイスへの、ピクセルの四角形に対応する色データのビット ブロック転送を実行します。

名前空間: System.Drawing
アセンブリ: System.Drawing (system.drawing.dll 内)
構文構文

Public Sub CopyFromScreen ( _
    sourceX As Integer, _
    sourceY As Integer, _
    destinationX As Integer, _
    destinationY As Integer, _
    blockRegionSize As Size _
)
Dim instance As Graphics
Dim sourceX As Integer
Dim sourceY As Integer
Dim destinationX As Integer
Dim destinationY As Integer
Dim blockRegionSize As Size

instance.CopyFromScreen(sourceX, sourceY, destinationX, destinationY, blockRegionSize)
public void CopyFromScreen (
    int sourceX,
    int sourceY,
    int destinationX,
    int destinationY,
    Size blockRegionSize
)
public:
void CopyFromScreen (
    int sourceX, 
    int sourceY, 
    int destinationX, 
    int destinationY, 
    Size blockRegionSize
)
public void CopyFromScreen (
    int sourceX, 
    int sourceY, 
    int destinationX, 
    int destinationY, 
    Size blockRegionSize
)
public function CopyFromScreen (
    sourceX : int, 
    sourceY : int, 
    destinationX : int, 
    destinationY : int, 
    blockRegionSize : Size
)

パラメータ

sourceX

転送元の四角形の左上隅の点の x 座標。

sourceY

転送元の四角形の左上隅の点の y 座標。

destinationX

転送先の四角形の左上隅の点の x 座標。

destinationY

転送先の四角形の左上隅の点の y 座標。

blockRegionSize

転送される領域のサイズ。

例外例外
解説解説

CopyFromScreen メソッドは、イメージを重ね合わせてレイアウトする場合に便利です。転送元と転送先の色のブレンド方法を指定するには、CopyPixelOperation パラメータを受け取るいずれかの CopyFromScreen メソッドを使用します。

使用例使用例

CopyFromScreen を使用して現在のフォームのコピーを出力する方法を次のコード例に示します。

Imports System
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
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());
    }
}
.NET Framework のセキュリティ.NET Framework のセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Graphics.CopyFromScreen メソッド (Point, Point, Size, CopyPixelOperation)

メモ : このメソッドは、.NET Framework version 2.0 で新しく追加されたものです。

画面から Graphics の描画サーフェイスへの、ピクセルの四角形に対応する色データのビット ブロック転送を実行します。

名前空間: System.Drawing
アセンブリ: System.Drawing (system.drawing.dll 内)
構文構文

Public Sub CopyFromScreen ( _
    upperLeftSource As Point, _
    upperLeftDestination As Point, _
    blockRegionSize As Size, _
    copyPixelOperation As CopyPixelOperation _
)
Dim instance As Graphics
Dim upperLeftSource As Point
Dim upperLeftDestination As Point
Dim blockRegionSize As Size
Dim copyPixelOperation As CopyPixelOperation

instance.CopyFromScreen(upperLeftSource, upperLeftDestination, blockRegionSize, copyPixelOperation)
public void CopyFromScreen (
    Point upperLeftSource,
    Point upperLeftDestination,
    Size blockRegionSize,
    CopyPixelOperation copyPixelOperation
)
public:
void CopyFromScreen (
    Point upperLeftSource, 
    Point upperLeftDestination, 
    Size blockRegionSize, 
    CopyPixelOperation copyPixelOperation
)
public void CopyFromScreen (
    Point upperLeftSource, 
    Point upperLeftDestination, 
    Size blockRegionSize, 
    CopyPixelOperation copyPixelOperation
)
public function CopyFromScreen (
    upperLeftSource : Point, 
    upperLeftDestination : Point, 
    blockRegionSize : Size, 
    copyPixelOperation : CopyPixelOperation
)

パラメータ

upperLeftSource

転送元の四角形の左上隅の点。

upperLeftDestination

転送先の四角形の左上隅の点。

blockRegionSize

転送される領域のサイズ。

copyPixelOperation

CopyPixelOperation 値の 1 つ。

例外例外
例外の種類条件

InvalidEnumArgumentException

copyPixelOperation が CopyPixelOperation のメンバではありません。

Win32Exception

操作に失敗しました。

解説解説
使用例使用例

CopyFromScreen メソッドを使用する方法の例を次に示します。この例を実行するには、コードを Windows フォームに貼り付けます。フォームの Paint イベントを処理し、e を PaintEventArgs として渡して、Paint イベント処理メソッドから CopyPixels2 メソッドを呼び出します。

Private Sub CopyPixels2(ByVal
 e As PaintEventArgs) 
    e.Graphics.CopyFromScreen(Me.Location, _
        New Point(40, 40), New Size(100, 100),
 _
        CopyPixelOperation.MergePaint)
End Sub
private void CopyPixels2(PaintEventArgs e)
{
    e.Graphics.CopyFromScreen(this.Location, new
 Point(40, 40), 
        new Size(100, 100), CopyPixelOperation.MergePaint); 
}
.NET Framework のセキュリティ.NET Framework のセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

Graphics.CopyFromScreen メソッド




英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「Graphics.CopyFromScreen」の関連用語

Graphics.CopyFromScreenのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



Graphics.CopyFromScreenのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS