BitmapMetadata.GetQuery(String) 方法

定义

提供对元数据查询读取器的访问,该读取器可从位图图像文件中提取元数据。

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 对象中查询的字符串。

返回

位于指定查询位置的元数据。

属性

例外

querynull

示例

下面的代码示例演示如何使用 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) 。

适用于

另请参阅