Clipboard.SetImage(Image) 方法

定義

清除剪貼簿,然後加入 Image 格式的 BitmapClears the Clipboard and then adds an Image in the Bitmap format.

public:
 static void SetImage(System::Drawing::Image ^ image);
public static void SetImage (System.Drawing.Image image);
static member SetImage : System.Drawing.Image -> unit
Public Shared Sub SetImage (image As Image)

參數

image
Image

要加入剪貼簿的 ImageThe Image to add to the Clipboard.

例外狀況

無法清除剪貼簿。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.

imagenullimage is null.

範例

下列範例示範這個成員。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 方法來判斷剪貼簿是否包含影像資料,然後再使用方法來抓取影像 GetImageTo retrieve image data from the Clipboard, first use the ContainsImage method to determine whether the Clipboard contains image data before retrieving it with the GetImage method.

注意

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.

適用於

另請參閱