Clipboard.GetImage 方法

定義

從剪貼簿擷取影像。Retrieves an image from the Clipboard.

public:
 static System::Drawing::Image ^ GetImage();
public static System.Drawing.Image GetImage ();
static member GetImage : unit -> System.Drawing.Image
Public Shared Function GetImage () As Image

傳回

Image

如果剪貼簿不包含任何 Image 格式或可以轉換為該格式的資料,則為代表剪貼簿影像資料或 nullBitmapAn Image representing the Clipboard image data or null if the Clipboard does not contain any data that is in the Bitmap format or can be converted to that format.

例外狀況

無法清除剪貼簿。The Clipboard could not be cleared. 這通常在剪貼簿由另一個處理序使用時發生。This typically occurs when the Clipboard is being used by another process.

目前執行緒 (Thread) 不是在單一執行緒 Apartment (STA) 模式。The current thread is not in single-threaded apartment (STA) mode. STAThreadAttribute 加入至應用程式的 Main 方法。Add the STAThreadAttribute to your application's Main method.

範例

下列範例示範這個成員。The following example demonstrates this member.

// Demonstrates SetImage, ContainsImage, and GetImage.
public System.Drawing.Image SwapClipboardImage(
    System.Drawing.Image replacementImage)
{
    System.Drawing.Image returnImage = null;
    if (Clipboard.ContainsImage())
    {
        returnImage = Clipboard.GetImage();
        Clipboard.SetImage(replacementImage);
    }
    return returnImage;
}
' Demonstrates SetImage, ContainsImage, and GetImage.
Public Function SwapClipboardImage( _
    ByVal replacementImage As System.Drawing.Image) _
    As System.Drawing.Image

    Dim returnImage As System.Drawing.Image = Nothing

    If Clipboard.ContainsImage() Then
        returnImage = Clipboard.GetImage()
        Clipboard.SetImage(replacementImage)
    End If

    Return returnImage
End Function

備註

ContainsImage 可以使用方法來判斷剪貼簿是否包含影像資料,然後再使用這個方法進行抓取。Use the ContainsImage method to determine whether the Clipboard contains image data before retrieving it with this method.

使用 SetImage 方法將影像資料新增至剪貼簿。Use the SetImage method to add image data to the Clipboard.

注意

Clipboard類別只能用在設定為單一線程單元 (STA) 模式的執行緒中。The Clipboard class can only be used in threads set to single thread apartment (STA) mode. 若要使用這個類別,請確定您的 Main 方法是以 STAThreadAttribute 屬性標記。To use this class, ensure that your Main method is marked with the STAThreadAttribute attribute.

適用於

另請參閱