public bool ParseDocument() { Goheer.EXIF.EXIFextractor er2 = new Goheer.EXIF.EXIFextractor(filename, "", "");//"F:\\webdev\\raw.images.pk\\saripaya\\lonely Tree - Paey.jpg", "", ""); string txtPage = String.Empty; foreach (DictionaryEntry de in er2) { switch (de.Key.ToString()) { case "Equip Make": //: SONY txtPage += " " + de.Value; break; case "Equip Model": // : DSC-H9 txtPage += " " + de.Value; break; default: txtPage = txtPage + de.Key + " : " + de.Value + Environment.NewLine; break; } } string xmp = GetXmpXmlDocFromImage(filename); if (!String.IsNullOrEmpty(xmp)) { LoadDoc(xmp); } return(true); }
/// <summary> /// 返回源文件的拍摄日期,用了EXIFEextactor第三方组件 /// </summary> /// <param name="serverFileName"></param> /// <param name="serverFolderName"></param> /// <param name="resourceType"></param> /// <param name="previewType"></param> /// <returns></returns> public static DateTime GetResourceShotDateTime(string serverFileName, string serverFolderName, string resourceType, string previewType) { DateTime dt = DateTime.MinValue; string filePath = string.Empty; string folder = string.Empty; if (resourceType.ToLower().Equals("image")) { IResourceType obj = new ImageType(); //yangguang //folder = obj.SourcePath; //folder = Path.Combine(folder, serverFolderName); //filePath = Path.Combine(folder, serverFileName); filePath = obj.GetSourcePath(serverFolderName, serverFileName); try { Goheer.EXIF.EXIFextractor er2 = new Goheer.EXIF.EXIFextractor(filePath, "", ""); string s = string.Empty; if (er2["DTDigitized"] != null) { s = er2["DTDigitized"].ToString(); } else if (er2["DTOrig"] != null) { s = er2["DTOrig"].ToString(); } else if (er2["Date Time"] != null) { s = er2["Date Time"].ToString(); } if (!string.IsNullOrEmpty(s)) { string[] arr = s.Split(" ".ToCharArray()); string s1 = arr[0].Replace(":", "-") + " " + arr[1]; dt = Convert.ToDateTime(s1.ToString()); } } catch (Exception ex) { LogWriter.WriteExceptionLog(ex); } } else if (resourceType.ToLower().Equals("video")) { } return(dt); }
protected Goheer.EXIF.EXIFextractor CheckEXIF(String file_path) { /// "Exif IFD" /// "Gps IFD" /// "New Subfile Type" /// "Subfile Type" /// "Image Width" /// "Image Height" /// "Bits Per Sample" /// "Compression" /// "Photometric Interp" /// "Thresh Holding" /// "Cell Width" /// "Cell Height" /// "Fill Order" /// "Document Name" /// "Image Description" /// "Equip Make" /// "Equip Model" /// "Strip Offsets" /// "Orientation" /// "Samples PerPixel" /// "Rows Per Strip" /// "Strip Bytes Count" /// "Min Sample Value" /// "Max Sample Value" /// "X Resolution" /// "Y Resolution" /// "Planar Config" /// "Page Name" /// "X Position" /// "Y Position" /// "Free Offset" /// "Free Byte Counts" /// "Gray Response Unit" /// "Gray Response Curve" /// "T4 Option" /// "T6 Option" /// "Resolution Unit" /// "Page Number" /// "Transfer Funcition" /// "Software Used" /// "Date Time" /// "Artist" /// "Host Computer" /// "Predictor" /// "White Point" /// "Primary Chromaticities" /// "ColorMap" /// "Halftone Hints" /// "Tile Width" /// "Tile Length" /// "Tile Offset" /// "Tile ByteCounts" /// "InkSet" /// "Ink Names" /// "Number Of Inks" /// "Dot Range" /// "Target Printer" /// "Extra Samples" /// "Sample Format" /// "S Min Sample Value" /// "S Max Sample Value" /// "Transfer Range" /// "JPEG Proc" /// "JPEG InterFormat" /// "JPEG InterLength" /// "JPEG RestartInterval" /// "JPEG LosslessPredictors" /// "JPEG PointTransforms" /// "JPEG QTables" /// "JPEG DCTables" /// "JPEG ACTables" /// "YCbCr Coefficients" /// "YCbCr Subsampling" /// "YCbCr Positioning" /// "REF Black White" /// "ICC Profile" /// "Gamma" /// "ICC Profile Descriptor" /// "SRGB RenderingIntent" /// "Image Title" /// "Copyright" /// "Resolution X Unit" /// "Resolution Y Unit" /// "Resolution X LengthUnit" /// "Resolution Y LengthUnit" /// "Print Flags" /// "Print Flags Version" /// "Print Flags Crop" /// "Print Flags Bleed Width" /// "Print Flags Bleed Width Scale" /// "Halftone LPI" /// "Halftone LPIUnit" /// "Halftone Degree" /// "Halftone Shape" /// "Halftone Misc" /// "Halftone Screen" /// "JPEG Quality" /// "Grid Size" /// "Thumbnail Format" /// "Thumbnail Width" /// "Thumbnail Height" /// "Thumbnail ColorDepth" /// "Thumbnail Planes" /// "Thumbnail RawBytes" /// "Thumbnail Size" /// "Thumbnail CompressedSize" /// "Color Transfer Function" /// "Thumbnail Data" /// "Thumbnail ImageWidth" /// "Thumbnail ImageHeight" /// "Thumbnail BitsPerSample" /// "Thumbnail Compression" /// "Thumbnail PhotometricInterp" /// "Thumbnail ImageDescription" /// "Thumbnail EquipMake" /// "Thumbnail EquipModel" /// "Thumbnail StripOffsets" /// "Thumbnail Orientation" /// "Thumbnail SamplesPerPixel" /// "Thumbnail RowsPerStrip" /// "Thumbnail StripBytesCount" /// "Thumbnail ResolutionX" /// "Thumbnail ResolutionY" /// "Thumbnail PlanarConfig" /// "Thumbnail ResolutionUnit" /// "Thumbnail TransferFunction" /// "Thumbnail SoftwareUsed" /// "Thumbnail DateTime" /// "Thumbnail Artist" /// "Thumbnail WhitePoint" /// "Thumbnail PrimaryChromaticities" /// "Thumbnail YCbCrCoefficients" /// "Thumbnail YCbCrSubsampling" /// "Thumbnail YCbCrPositioning" /// "Thumbnail RefBlackWhite" /// "Thumbnail CopyRight" /// "Luminance Table" /// "Chrominance Table" /// "Frame Delay" /// "Loop Count" /// "Pixel Unit" /// "Pixel PerUnit X" /// "Pixel PerUnit Y" /// "Palette Histogram" /// "Exposure Time" /// "F-Number" /// "Exposure Prog" /// "Spectral Sense" /// "ISO Speed" /// "OECF" /// "Ver" /// "DTOrig" /// "DTDigitized" /// "CompConfig" /// "CompBPP" /// "Shutter Speed" /// "Aperture" /// "Brightness" /// "Exposure Bias" /// "MaxAperture" /// "SubjectDist" /// "Metering Mode" /// "LightSource" /// "Flash" /// "FocalLength" /// "Maker Note" /// "User Comment" /// "DTSubsec" /// "DTOrigSS" /// "DTDigSS" /// "FPXVer" /// "ColorSpace" /// "PixXDim" /// "PixYDim" /// "RelatedWav" /// "Interop" /// "FlashEnergy" /// "SpatialFR" /// "FocalXRes" /// "FocalYRes" /// "FocalResUnit" /// "Subject Loc" /// "Exposure Index" /// "Sensing Method" /// "FileSource" /// "SceneType" Bitmap bmp = new Bitmap(file_path); Goheer.EXIF.EXIFextractor er = new Goheer.EXIF.EXIFextractor(ref bmp, "\n"); //MsgBox(er.Item("ISO Speed")) return er; }
/// <summary> /// Reads the exif data of the image /// </summary> /// <param name="file">The image file</param> /// <returns>exif_data object</returns> private exif_data GetImageExifData(string file) { Goheer.EXIF.EXIFextractor exif = new Goheer.EXIF.EXIFextractor(file, "", ""); exif_data exifData = new exif_data(); try { foreach (System.Web.UI.Pair s in exif) { switch (s.First.ToString().ToLower()) { case "aperture": exifData.aperture = s.Second.ToString(); break; case "f-number": exifData.aperture = s.Second.ToString(); break; case "shutter speed": exifData.shutter_speed = s.Second.ToString(); break; case "equip model": exifData.camera = s.Second.ToString(); break; case "iso speed": exifData.iso = s.Second.ToString(); break; case "date time": exifData.date_taken = s.Second.ToString(); break; case "focallength": exifData.focal_length = s.Second.ToString(); break; default: break; } } } catch { } return exifData; }
/// <summary> /// 返回源文件的拍摄日期,用了EXIFEextactor第三方组件 /// </summary> /// <param name="serverFileName"></param> /// <param name="serverFolderName"></param> /// <param name="resourceType"></param> /// <param name="previewType"></param> /// <returns></returns> public static DateTime GetResourceShotDateTime(string serverFileName,string serverFolderName,string resourceType,string previewType) { DateTime dt=DateTime.MinValue; string filePath = string.Empty; string folder = string.Empty; if (resourceType.ToLower().Equals("image")) { IResourceType obj = new ImageType(); //yangguang //folder = obj.SourcePath; //folder = Path.Combine(folder, serverFolderName); //filePath = Path.Combine(folder, serverFileName); filePath = obj.GetSourcePath(serverFolderName, serverFileName); try { Goheer.EXIF.EXIFextractor er2 = new Goheer.EXIF.EXIFextractor(filePath, "", ""); string s = string.Empty; if (er2["DTDigitized"] != null) { s = er2["DTDigitized"].ToString(); } else if (er2["DTOrig"] != null) { s = er2["DTOrig"].ToString(); } else if (er2["Date Time"] != null) { s = er2["Date Time"].ToString(); } if (!string.IsNullOrEmpty(s)) { string[] arr = s.Split(" ".ToCharArray()); string s1 = arr[0].Replace(":", "-") + " " + arr[1]; dt = Convert.ToDateTime(s1.ToString()); } } catch (Exception ex) { LogWriter.WriteExceptionLog(ex); } } else if (resourceType.ToLower().Equals("video")) { } return dt; }
/// <summary> /// Extract Title, Description, Keywords (tags), Make, Model from image /// </summary> public override bool Populate() { string filename = PathAndName; this.Title = System.IO.Path.GetFileNameWithoutExtension(filename); try { Goheer.EXIF.EXIFextractor er2 = new Goheer.EXIF.EXIFextractor(filename, "",""); foreach (DictionaryEntry de in er2) { switch (de.Key.ToString()) { case "Equip Make"://: SONY _WordsOnly += " " + de.Value.ToString().Trim(new char[] { '\0' }); break; case "Equip Model": // : DSC-H9 _WordsOnly += " " + de.Value.ToString().Trim(new char[] { '\0' }); break; default: _WordsOnly = _WordsOnly + de.Key + " : " + de.Value + Environment.NewLine; break; } } string xmp = GetXmpXmlDocFromImage(filename); LoadDoc(xmp); _WordsOnly += " " + Title; _WordsOnly += " " + Description; foreach (string k in Keywords) _WordsOnly += " " + k; // So they're indexed.. _WordsOnly = System.Text.RegularExpressions.Regex.Replace(_WordsOnly, @"[^\w0-9,. ]", "", System.Text.RegularExpressions.RegexOptions.IgnoreCase); this.All = _WordsOnly; } catch (Exception ex) { throw new Exception("Jpeg info extraction failed. Exception : " + ex.Message, ex); } if (this.All != string.Empty) { if (this.Description == string.Empty) { // if no description was set, use the rest of the text this.Description = base.GetDescriptionFromWordsOnly(WordsOnly); } return true; } else { return false; } }