共用方式為


BitmapMetadata.SetQuery(String, Object) 方法

定義

提供中繼資料查詢讀取器的存取權,該讀取器可將中繼資料寫入點陣圖影像檔。

public:
 void SetQuery(System::String ^ query, System::Object ^ value);
[System.Security.SecurityCritical]
public void SetQuery (string query, object value);
public void SetQuery (string query, object value);
[<System.Security.SecurityCritical>]
member this.SetQuery : string * obj -> unit
member this.SetQuery : string * obj -> unit
Public Sub SetQuery (query As String, value As Object)

參數

query
String

識別要寫入之中繼資料的位置。

value
Object

要寫入的中繼資料值。

屬性

範例

下列程式碼範例示範如何使用 SetQuery 方法,將中繼資料寫入至可攜式網狀圖形 (PNG) 檔案。

Stream^ pngStream = gcnew FileStream("smiley.png", FileMode::Open, FileAccess::ReadWrite, FileShare::ReadWrite);
PngBitmapDecoder^ pngDecoder = gcnew PngBitmapDecoder(pngStream, BitmapCreateOptions::PreservePixelFormat, BitmapCacheOption::Default);
BitmapFrame^ pngFrame = pngDecoder->Frames[0];
InPlaceBitmapMetadataWriter^ pngInplace = pngFrame->CreateInPlaceBitmapMetadataWriter();
if (pngInplace->TrySave() == true)
{
   pngInplace->SetQuery("/Text/Description", "Have a nice day.");
}
pngStream->Close();
Stream pngStream = new System.IO.FileStream("smiley.png", FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
PngBitmapDecoder pngDecoder = new PngBitmapDecoder(pngStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default);
BitmapFrame pngFrame = pngDecoder.Frames[0];
InPlaceBitmapMetadataWriter pngInplace = pngFrame.CreateInPlaceBitmapMetadataWriter();
if (pngInplace.TrySave() == true)
{ pngInplace.SetQuery("/Text/Description", "Have a nice day."); }
pngStream.Close();
Dim pngStream As New System.IO.FileStream("smiley.png", FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite)
Dim pngDecoder As New PngBitmapDecoder(pngStream, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.Default)
Dim pngFrame As BitmapFrame = pngDecoder.Frames(0)
Dim pngInplace As InPlaceBitmapMetadataWriter = pngFrame.CreateInPlaceBitmapMetadataWriter()
If pngInplace.TrySave() = True Then
    pngInplace.SetQuery("/Text/Description", "Have a nice day.")
End If
pngStream.Close()

寫入中繼資料之後, GetQuery 方法會用來讀取該資料,並將它發出為文字字串。


// Add the metadata of the bitmap image to the text block.
TextBlock^ myTextBlock = gcnew TextBlock();
myTextBlock->Text = "The Description metadata of this image is: " + pngInplace->GetQuery("/Text/Description")->ToString();

// Add the metadata of the bitmap image to the text block.
TextBlock myTextBlock = new TextBlock();
myTextBlock.Text = "The Description metadata of this image is: " + pngInplace.GetQuery("/Text/Description").ToString();
' Add the metadata of the bitmap image to the text block.
Dim myTextBlock As New TextBlock()
myTextBlock.Text = "The Description metadata of this image is: " + pngInplace.GetQuery("/Text/Description").ToString()

備註

與影像相關聯的中繼資料是描述影像但不需要顯示影像的資料。 每個支援的點陣圖影像格式會以不同的方式處理中繼資料,但讀取和寫入中繼資料的設施相同。

Windows Presentation Foundation (WPF) 支援下列影像中繼資料架構:Exchangeable image file (Exif) 、tEXt (PNG 文字資料) 、image file directory (IFD) 、International Press T電信委員會 (IPTC) (,以及 XMP) 。

適用於

另請參閱