本文介绍了BitmapMetaData在TIFF文件上引发COM异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些代码,可以使用presentationcore简单地从各种图像文件中读取元数据.我们的质量检查人员发现了一些失败的TIFF文件.发生的情况是,尝试访问BitmapMetaData对象的属性(例如Author,ApplicationName等)都将引发System.Runtime.InteropServices.COMException.值得注意的是,并非所有TIFF文件都会发生这种情况.此外,有问题的文件的元数据不会出现在资源管理器的属性对话框中.

这是代码:

I have code that simply reads in the meta data from a variety of image files using presentationcore.   Our QA folks have identified a few TIFF files that fail.  What happens is that attempts to access the properties of the BitmapMetaData object such as Author, ApplicationName, etc all throw a System.Runtime.InteropServices.COMException.   Of note is that this doesn't happen to all TIFF files.  In addition, the problematic files have their metadata show up in the properties dialog of explorer with no problem.

Here's the code:

            FileInfo file = new FileInfo(@"\\server\share\somefile.TIFF");
            try
            {
                // We'll create the file stream ourselves so we can guarantee that the underlying file will be released
                using (FileStream fileStream = file.OpenRead())
                {
                    BitmapSource img = BitmapFrame.Create(fileStream);
                    if (img != null)
                    {
                        BitmapMetadata metaData = img.Metadata as BitmapMetadata;

                        if (metaData != null)
                        {
                            if (metaData.Author != null)  // Throws exeception on this TIFF!
                            {
                                foreach (string currAuthor in metaData.Author)
                                    base.AddTextString(currAuthor);
                            }
                            base.AddTextString(metaData.ApplicationName);      // Throws exeception on this TIFF!
                            base.AddTextString(metaData.CameraManufacturer);  // Throws exeception on this TIFF!
                            base.AddTextString(metaData.CameraModel);  // Throws exeception on this TIFF!
                            base.AddTextString(metaData.Comment);  // Throws exeception on this TIFF!
                            base.AddTextString(metaData.Copyright);  // Throws exeception on this TIFF!
                            base.AddTextString(metaData.DateTaken);  // Throws exeception on this TIFF!
                            base.AddTextString(metaData.Format);  // Throws exeception on this TIFF!
                            if (metaData.Keywords != null)  // Throws exeception on this TIFF!
                            {
                                foreach (string currKeyword in metaData.Keywords)
                                    base.AddTextString(currKeyword);
                            }
                            base.AddTextString(metaData.Location);  // Throws exeception on this TIFF!
                            base.AddTextString(metaData.Subject);  // Throws exeception on this TIFF!
                            base.AddTextString(metaData.Title);  // Throws exeception on this TIFF!
                        }
                    }
                }
            }
            catch (ComException)
            {
                // Some TIFF files wind up here 100% of the time.
            }



特定的HRESULT只是0x80004005(E_FAIL)
是否有人知道出了什么问题?
谢谢!



The particular HRESULT is simply 0x80004005 (E_FAIL)
Does anyone have any idea what may be going wrong?
Thanks!

推荐答案


这篇关于BitmapMetaData在TIFF文件上引发COM异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-22 21:42