如何查看网站蜘蛛,冠县哪做网站,在线编辑ppt的网站,网站建设策划实施要素有哪些近期公司组织了书画摄影比赛#xff0c;本人作为摄影爱好者#xff0c;平时也会拍些照片#xff0c;这次比赛当然不能错过。为了提高获奖概率#xff0c;选了19张图像作为参赛作品。但是#xff0c;摄影作品要提交图像的光圈、曝光时间等参数。一两张还可以通过电脑自带软…近期公司组织了书画摄影比赛本人作为摄影爱好者平时也会拍些照片这次比赛当然不能错过。为了提高获奖概率选了19张图像作为参赛作品。但是摄影作品要提交图像的光圈、曝光时间等参数。一两张还可以通过电脑自带软件右键查看图像参数并一个个复制但现在有19张让我一点点复制还不如直接放弃参与了。谁让咱们还有一个身份是coder那就现场手撸个小程序批量输出图像的EXIF信息。
开发需求很简单就是能手动选取一个文件夹然后读取该路径下的所有文件图片然后提取每张图像的exif信息并将结果显示到界面然后将Ctrl A复制所有信息即可。在开发上语言选择c#搭配WPF框架并选择ExifLib这个轻量化的EXIF信息提取库获取图像参数信息下图是最终的提取信息。 XAML主要代码 GridGrid.RowDefinitionsRowDefinition Height*/RowDefinition Heightauto//Grid.RowDefinitionsTextBox x:NametextBox Grid.Row0/Button Content请选择一个路径 ClickButton_Click Grid.Row1 BackgroundLightBlue Margin2,0,2,2 Padding5 //Gridcs逻辑代码 using ExifLib;private void Button_Click(object sender, RoutedEventArgs e){// 创建一个选择文件路径的对话框OpenFileDialog openFileDialog new OpenFileDialog();openFileDialog.Multiselect false;openFileDialog.CheckFileExists false;openFileDialog.FileName Folder Selection.;openFileDialog.Filter Folders|no.files;Dictionarystring, string dic_pathAndName new Dictionarystring, string();if (openFileDialog.ShowDialog() true){string folderPath System.IO.Path.GetDirectoryName(openFileDialog.FileName);// 使用 DirectoryInfo 类获取该路径下的所有文件DirectoryInfo directoryInfo new DirectoryInfo(folderPath);FileInfo[] fileInfos directoryInfo.GetFiles();// 处理获取到的文件foreach (FileInfo fileInfo in fileInfos){Debug.WriteLine(fileInfo.Name);//dic_pathAndName[System.IO.Path.GetFileNameWithoutExtension(fileInfo.FullName)] fileInfo.FullName;//key为没有后缀名的文件名dic_pathAndName[fileInfo.Name] fileInfo.FullName;}}if (dic_pathAndName.Count 0) return;foreach (var dic in dic_pathAndName){Debug.WriteLine(${dic.Key}: {getImageExifInfo(dic.Value)});textBox.AppendText(${dic.Key}, {getImageExifInfo(dic.Value)}\n);}}string getImageExifInfo(string path){if (!File.Exists(path)) return ;string res ;try{using (ExifReader reader new ExifReader(path)){// 相机制造商if (reader.GetTagValue(ExifTags.Make, out string make))Debug.WriteLine(相机制造商: make);// 相机型号if (reader.GetTagValue(ExifTags.Model, out string model))Debug.WriteLine(相机型号: model);// 光圈if (reader.GetTagValue(ExifTags.FNumber, out double fNumber)){var fNumberFraction FractionFromDouble(fNumber);Debug.WriteLine(光圈: F/ fNumber);}string time ;// 快门速度if (reader.GetTagValue(ExifTags.ExposureTime, out double exposureTime)){var exposureTimeFraction FractionFromDouble(exposureTime);time exposureTimeFraction.Item1 / exposureTimeFraction.Item2;}// ISOif (reader.GetTagValue(ExifTags.ISOSpeedRatings, out ushort isoSpeedRatings))Debug.WriteLine(ISO: isoSpeedRatings); 曝光时间//if (reader.GetTagValue(ExifTags.ExposureTime, out double exposureTime))// Debug.WriteLine(曝光时间: exposureTime.ToString(0.##) s);// 焦距if (reader.GetTagValue(ExifTags.FocalLength, out double focalLength))Debug.WriteLine(焦距: focalLength.ToString(0.##) mm);res ${model} f/{fNumber} {time}s ISO-{isoSpeedRatings} {focalLength}mm;}}catch (Exception e){}return res;}private Tupleint, int FractionFromDouble(double value, double error 0.0001){int denominator 1;while (Math.Abs(value * denominator - Math.Round(value * denominator)) error)denominator;return Tuple.Create((int)Math.Round(value * denominator), denominator);}以上代码直接复制、拷贝走然后可以根据自己的需求输出想要的图像参数信息并随意定义文本格式爽歪歪。