BitmapMetadata.GetQuery(String) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
存取可從點陣圖影像檔擷取中繼資料的中繼資料查詢讀取器。
public:
System::Object ^ GetQuery(System::String ^ query);
[System.Security.SecurityCritical]
public object GetQuery (string query);
public object GetQuery (string query);
[<System.Security.SecurityCritical>]
member this.GetQuery : string -> obj
member this.GetQuery : string -> obj
Public Function GetQuery (query As String) As Object
參數
- query
- String
識別目前 BitmapMetadata 物件中正在進行查詢的字串。
傳回
在指定查詢位置的中繼資料。
- 屬性
例外狀況
query
為 null
。
範例
下列程式碼範例示範如何使用 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) 。