BitmapMetadata.SetQuery(String, Object) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
提供一個能將元資料寫入點陣圖影像檔的元資料查詢編輯器。
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())
{
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())
{ 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)支援以下影像元資料架構:可交換影像檔案(Exif)、tEXt(PNG 文字資料)、影像檔案目錄(IFD)、國際新聞電信理事會(IPTC)及可擴充元資料平台(XMP)。