using System; using System.Collections; using System.IO; using com.drew.metadata; using com.drew.imaging.jpg; using com.utils; /// /// This class was first written by Drew Noakes in Java. /// /// This is public domain software - that is, you can do whatever you want /// with it, and include it software that is licensed under the GNU or the /// BSD license, or whatever other licence you choose, including proprietary /// closed source licenses. I do ask that you leave this header in tact. /// /// If you make modifications to this code that you think would benefit the /// wider community, please send me a copy and I'll post it on my site. /// /// If you make use of this code, Drew Noakes will appreciate hearing /// about it: drew@drewnoakes.com /// /// Latest Java version of this software kept at /// http://drewnoakes.com/ /// /// The C# class was made by Ferret Renaud: /// renaud91@free.fr /// If you find a bug in the C# code, feel free to mail me. /// namespace com.drew.metadata.jpeg { /// /// The Jpeg reader class /// public class JpegCommentReader : MetadataReader { /// /// The COM data segment. /// private byte[] _data; /// /// Creates a new JpegReader for the specified Jpeg jpegFile. /// /// where to read public JpegCommentReader(FileInfo jpegFile) : this( new JpegSegmentReader(jpegFile).ReadSegment( JpegSegmentReader.SEGMENT_COM)) { } /// /// Creates a new JpegReader for the specified Jpeg jpegFile. /// /// where to read public JpegCommentReader(byte[] data) { _data = data; } /// /// Performs the Jpeg data extraction, returning a new instance of Metadata. /// /// a new instance of Metadata public Metadata Extract() { return Extract(new Metadata()); } /// /// Extracts metadata /// /// where to add metadata /// the metadata found public Metadata Extract(Metadata metadata) { if (_data == null) { return metadata; } JpegCommentDirectory directory = (JpegCommentDirectory) metadata.GetDirectory( Type.GetType("com.drew.metadata.jpeg.JpegCommentDirectory")); directory.SetObject( JpegCommentDirectory.TAG_JPEG_COMMENT, Utils.Decode(_data, true)); return metadata; } } }