的GifBitmapDe codeR读取元数据属性...为什么是空? [英] Reading Metadata property of GifBitmapDecoder...why is it null?
问题描述
我如何可以读取的延迟,左侧和顶部偏移数据为GIF的每一帧?我至今获得这样的。
-
加载的Gif
VAR myGif =新GifBitmapDe codeR(URI,BitmapCreateOptions preservePixelFormat,BitmapCacheOption.OnLoad。);
-
获取帧
VAR帧= myGif.Frames [我];
-
从 MSDN:原生图像格式元数据查询读
李>(USHORT)Metadata.GetQuery(/ grctlext /延迟)
,(USHORT)Metadata.GetQuery (/ imgdesc /左)
,(USHORT)Metadata.GetQuery(/ imgdesc /顶)
但是有两件事不能正常工作。首先无论是GIF和框架的元数据属性总是空,即使我尝试不同的GIF动画文件。第二,该帧的元数据属性似乎不具有GetQuery方法
我如何运行这些查询,我错过了什么?
编辑:
下面是一个示例code,让我空的元数据。使用全新安装的VS2010 premium,在一个新的WPF应用程序。图像文件是一个在注释。
使用系统;
使用System.Collections.Generic;
使用System.Linq的;
使用System.Text;
使用System.Windows;
使用System.Windows.Controls的;
使用System.Windows.Data;
使用System.Windows.Documents;
使用System.Windows.Input;
使用System.Windows.Media;
使用System.Windows.Media.Imaging;
使用System.Windows.Navigation;
使用System.Windows.Shapes;
命名空间WpfApplication1
{
///<总结>
///为MainWindow.xaml交互逻辑
///< /总结>
公共部分类主窗口:窗口
{
公共主窗口()
{
的InitializeComponent();
VAR URI =新的URI(@C:\ B-414328-animated_gif_.gif);
VAR myGif =新GifBitmapDe codeR(URI,BitmapCreateOptions preservePixelFormat,BitmapCacheOption.OnLoad。);
VAR帧= myGif.Frames [0];
标题=;
标题+ =环球元数据为空:+(myGif.Metadata == NULL)的ToString();
标题+ =;元数据框架为空:+(frame.Metadata == NULL)的ToString();
//崩溃由于无效的元数据
// VAR frameData =(BitmapMetadata)frame.Metadata;
// VAR率=(USHORT)frameData.GetQuery(/ grctlext /延迟);
}
}
}
首先,你需要的冻结的框架要获取元数据:
VAR帧= myGif.Frames [0];
frame.Freeze();
二,frame.Metadata返回 ImageMetadata < /一>不具有一个GetQuery方法,但实际上返回的对象的类型是 BitmapMetadata A>其中有一个<一个href="http://msdn.microsoft.com/en-us/library/system.windows.media.imaging.bitmapmetadata.getquery.aspx"相对=nofollow> GetQuery 方法,所以你只需要投frame.Metadata到BitmapMetadata,你在你的code中的最后一个注释行做的。
How can I read the delay, left and top offset data for each frame of a gif? I've gotten this far.
Load the Gif
var myGif = new GifBitmapDecoder(uri, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad);
Get a frame
var frame = myGif.Frames[i];
From MSDN: Native Image Format Metadata Queries read
(ushort)Metadata.GetQuery("/grctlext/Delay")
,(ushort)Metadata.GetQuery("/imgdesc/Left")
,(ushort)Metadata.GetQuery("/imgdesc/Top")
But two things don't work. First the Metadata property of both the gif and the frame are always null, even if I try different animated gif files. Second, the Metadata property of the frame doesn't seem to have a GetQuery method.
How do I run these queries, what did I miss?
Edit:
Here is sample code that gives me null metadata. Using a fresh install of VS2010 Premium, on a fresh WPF application. The image file is the one in the comments.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace WpfApplication1
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
var uri = new Uri(@"c:\b-414328-animated_gif_.gif");
var myGif = new GifBitmapDecoder(uri, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad);
var frame = myGif.Frames[0];
Title = "";
Title += "Global Metadata is null: " + (myGif.Metadata == null).ToString();
Title += "; Frame Metadata is null: " + (frame.Metadata == null).ToString();
// Crash due to null metadata
//var frameData = (BitmapMetadata)frame.Metadata;
//var rate = (ushort)frameData.GetQuery("/grctlext/Delay");
}
}
}
First, you need to Freeze the Frame you want to obtain the metadata from:
var frame = myGif.Frames[0];
frame.Freeze();
Second, the frame.Metadata returns an ImageMetadata which does not have a GetQuery method, but in fact the object returned is of type BitmapMetadata which has a GetQuery method, so you just need to cast frame.Metadata to BitmapMetadata as you do in the last commented lines of your code.
这篇关于的GifBitmapDe codeR读取元数据属性...为什么是空?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!