我正在收集大量照片的EXIF数据的轻量统计数据,我正在尝试找到将曝光时间值转换为可用数据<的最简单方法(即性能无关紧要) / em>的。 (据我所知)没有相机制造商可能使用的标准的标准,即我不能只是扫描网页上的随机图像和硬编码地图。
以下是我遇到的一组示例值(“表示秒数):
279“,30”,5“,3.2”,1.6“,1.3”,1“,1 / 1.3,1 / 1.6,1 / 2,1 / 2.5,1 / 3,1 / 4,1 / 5,1 / 8,1 / 13,1 / 8000,1 / 16000
还要考虑到我还想找到平均值(平均值)......但它应该是收集的实际快门速度之一,而不仅仅是一些任意数字。
编辑: 通过可用数据我的意思是某种创意?编号系统,我可以转换为/从进行计算。我想过将所有东西乘以1,000,000,除了分割时的一些分数是非常奇特的。
编辑#2:编辑#2: 为了澄清,我使用的是ExposureTime而不是ShutterSpeed,因为它包含摄影师友好的值,例如1/50。 ShutterSpeed更接近于近似值(在相机制造商之间有所不同),并导致1/49等值。答案 0 :(得分:2)
您希望将它们解析为某种持续时间对象。
查看该数据的一种简单方法是检查“或/发生,如果”解析为秒,/解析为秒的分数。我真的不明白你还有什么意思。例如,您需要指定一种语言 - 此外,可能还有一个解析器。
答案 1 :(得分:1)
快门速度在EXIF元数据中编码为SRATIONAL,分子为32位,分母为32位。使用System.Drawing:
检索它的示例代码 var bmp = new Bitmap(@"c:\temp\canon-ixus.jpg");
if (bmp.PropertyIdList.Contains(37377)) {
byte[] spencoded = bmp.GetPropertyItem(37377).Value;
int numerator = BitConverter.ToInt32(spencoded, 0);
int denominator = BitConverter.ToInt32(spencoded, 4);
Console.WriteLine("Shutter speed = {0}/{1}", numerator, denominator);
}
输出:快门速度= 553859/65536,样本图像retrieved here。
答案 2 :(得分:1)
您将遇到三种类型的字符串:
"
秒的字符串1/
我建议您只测试这些条件并使用浮点数相应地解析值:
string[] InputSpeeds = new[] { "279\"", "30\"", "5\"", "3.2\"", "1.6\"", "1.3\"", "1\"", "1/1.3", "1/1.6", "1/2", "1/2.5", "1/3", "1/4", "1/5", "1/8", "1/13", "1/8000", "1/16000" };
List<float> OutputSpeeds = new List<float>();
foreach (string s in InputSpeeds)
{
float ConvertedSpeed;
if (s.Contains("\""))
{
float.TryParse(s.Replace("\"", String.Empty), out ConvertedSpeed);
OutputSpeeds.Add(ConvertedSpeed);
}
else if (s.Contains("1/"))
{
float.TryParse(s.Remove(0, 2), out ConvertedSpeed);
if (ConvertedSpeed == 0)
{
OutputSpeeds.Add(0F);
}
else
{
OutputSpeeds.Add(1 / ConvertedSpeed);
}
}
else
{
float.TryParse(s, out ConvertedSpeed);
OutputSpeeds.Add(ConvertedSpeed);
}
}
如果您希望TimeSpan
只需将List<float>
更改为List<TimeSpan>
,而不是将浮点数添加到列表中,请使用TimeSpan.FromSeconds(ConvertedSpeed);