本文介绍了Tiff元数据gobbledegook的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

最近给我分配了一个作业,其中涉及从TIFF文件中读取元数据信息并使用/显示它.我已经看过这种想法的一些实现(例如MetaDataExtractor和FreeImage),但在这种情况下似乎都无法正常工作. MDE仅适用于jpg,这是其局限性. FreeImage完全用C(或C ++)编写,我想用C#编写.

当我尝试自己编写代码来完成此任务时,我得到的大部分东西因为元数据是垃圾.我尝试了以下几种不同的方法:

我尝试的第一种方法是使用Image.FromFile加载tif图像,创建一个StreamWriter,然后为图像的PropertyItems属性中的每个PropertyItem调用一个函数,该函数创建一个与Value属性的字节数组等效的字符串,并将该字符串写入StreamWriter.创建等效字符串的函数仅在字节数组中的每个字节上调用System.Convert.ToChar()并将其附加到返回结果中.

此方法导致一些非乱码的信息被放入输出文件,而大多数文件是完全不可读的.我为作家尝试了各种编码,其中很少能产生可远程读取的内容.


我尝试的第二种方法是与上面的方法相同,只是当我调用ConvertFromBytes函数时(函数(将字节数组转换为字符串的函数),我改为调用Encoding的GetString函数,该函数接受字节数组并返回等效的字符串.这似乎也无济于事.


我在想第二种方法可能在写出某些东西时对其进行了两次编码.显然,这是一件坏事.因此,我转而使用两个foreach循环-一个循环遍历PropertyItems,另一个循环遍历字节.然后,我将字节转换为char并将它们写出到流中.不过,这与第一种方法的功能大致相同.

我不太确定从何处去.我的问题是字节实际上可能不是要表示字符,而是其他数据类型,例如short,有理数等吗?有什么方法比我在字符串中获取tif文件中的标签的Value(而不是字节数组)更容易的方法吗?除上述方法外,我还尝试了其他方法,但这些方法似乎更加糟糕,不值得一提.

我正在使用.NET 2.0,VS2005.如果您需要更多信息,请不要毫不犹豫地发布.不管怎样,谢谢您的帮助.

Hi all,

I've been given an assignment recently that involves reading the metadata information out of a TIFF file and using/displaying it. I've looked at a few implementations of such an idea (such as MetaDataExtractor and FreeImage), but none seem to work in this case. MDE only works on jpgs, which is its limitation. FreeImage is written entirely in C (or maybe C++), and I'd like to have this written in C#.

When I've tried to write the code to do this myself, most of what I get back for the metadata is garbage. I have tried a few different ways, elaborated below:

The first method I tried was to simply load the tif image using Image.FromFile, create a StreamWriter, then for each PropertyItem in the image's PropertyItems property, call a function that creates a string equivalent of the byte array of the Value property and write that string to the StreamWriter. The function that creates a string equivalent just calls System.Convert.ToChar() on each byte in the byte array and appends it to the return result.

This method results in some non-garbled information being put into the output file, while most of it is completely unreadable. I tried various Encodings for the writer, very few of which produced anything that was remotely readable.


The second method I tried was to do the same as above, except when I call my ConvertFromBytes function (the function that converts a byte array to a string), I instead call an Encoding's GetString function, which takes in a byte array and returns the equivalent string. This doesn't seem to help at all, either.


I'm thinking that the second method was probably encoding something twice when writing it out. Obviously that's a bad thing. Because of that, I switched to using two foreach loops - one to loop over the PropertyItems and one to loop over the bytes. Then I cast the bytes to chars and write them out to the stream. This does approximately the same thing as the first method, though.

I'm not really sure where to go from here. Is my problem that the bytes may not actually be meant to represent chars, but rather other data types, such as short, rational, etc? Is there some way that is easier than what I'm doing to get at the Value of a tag in a tif file as a string (rather than a byte array)? I have tried other ways even than the above, but those all seemed to be even worse and not really worth mentioning.

I'm using .NET 2.0, VS 2005. If you need anymore information, don't hesitate to post. Thank you for your help, regardless.

推荐答案


这篇关于Tiff元数据gobbledegook的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 19:12