BitmapMetadata.SetQuery(String, Object) Methode

Definition

Bietet Zugriff auf einen Metadatenabfrage-Writer, der Metadaten in eine Bitmapbilddatei schreiben kann.

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)

Parameter

query
String

Gibt den Speicherort der zu schreibenden Metadaten an.

value
Object

Der Wert der zu schreibenden Metadaten.

Attribute

Beispiele

Im folgenden Codebeispiel wird die Verwendung der SetQuery Methode zum Schreiben von Metadaten in eine PNG-Datei (Portable Network Graphics) veranschaulicht.

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()

Nachdem die Metadaten geschrieben wurden, wird die GetQuery Methode zum Lesen dieser Daten und zum Ausgeben als Textzeichenfolge verwendet.


// 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()

Hinweise

Metadaten, die einem Bild zugeordnet sind, sind Daten, die das Bild beschreiben, aber nicht für die Anzeige des Bilds erforderlich sind. Jedes unterstützte Bitmapbildformat behandelt Metadaten unterschiedlich, aber die Möglichkeit zum Lesen und Schreiben von Metadaten ist identisch.

Windows Presentation Foundation (WPF) unterstützt die folgenden Bildmetadatenschemas: Exchangeable Image File (Exif), tEXt (PNG Textual Data), Image File Directory (IFD), International Press Telecommunications Council (IPTC) und Extensible Metadata Platform (XMP).

Gilt für:

Weitere Informationen