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() == 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) 支持以下图像元数据架构:可交换图像文件 (Exif) 、tEXt (PNG 文本数据) 、图像文件目录 (IFD) 、国际新闻电信理事会 (IPTC) 和可扩展元数据平台 (XMP) 。