18 private static readonly Dictionary<int, ExifTagName> names = GetNames();
20 private static Dictionary<int, ExifTagName> GetNames()
22 Dictionary<int, ExifTagName> Names =
new Dictionary<int, ExifTagName>();
25 Names[(int)Value] = Value;
58 Reader.BigEndian =
false;
62 Reader.BigEndian =
true;
77 int Pos = RefPos + (int)Offset.Value;
78 if (Pos < Reader.Position || Pos >= Reader.
Length)
81 Reader.Position = Pos;
95 if (!names.TryGetValue(TagID, out
ExifTagName Name))
107 int NrElements = (int)Count.Value;
137 int RecSize = (int)(Count.Value * ElementSize);
142 PosBak = Reader.Position + 4;
145 uint? ValueOffset = Reader.
NextLONG();
146 if (!ValueOffset.HasValue || RefPos + ValueOffset.Value > Reader.
Length)
150 Reader.Position = RefPos + (int)ValueOffset.Value;
166 byte[] Items =
new byte[NrElements];
168 for (j = 0; j < NrElements; j++)
197 ushort[] Items =
new ushort[NrElements];
199 for (j = 0; j < NrElements; j++)
205 Items[j] = (ushort)i;
225 uint[] Items =
new uint[NrElements];
227 for (j = 0; j < NrElements; j++)
247 uint NumeratorValue = u.Value;
253 uint DenominatorValue = u.Value;
260 for (j = 0; j < NrElements; j++)
266 uint NumeratorValue = u.Value;
272 uint DenominatorValue = u.Value;
274 Items[j] =
new Rational(NumeratorValue, DenominatorValue);
292 byte[] Items =
new byte[NrElements];
294 for (j = 0; j < NrElements; j++)
318 int[] Items =
new int[NrElements];
320 for (j = 0; j < NrElements; j++)
326 Items[j] = (int)u.Value;
340 int NumeratorValue = (int)u.Value;
346 int DenominatorValue = (int)u.Value;
353 for (j = 0; j < NrElements; j++)
359 int NumeratorValue = (int)u.Value;
365 int DenominatorValue = (int)u.Value;
375 Reader.Position = PosBak;
381 if (!Offset.HasValue)
384 if (Offset.Value == 0)
387 Pos = RefPos + (int)Offset.Value;
388 if (Pos < Reader.Position || Pos >= Reader.
Length)
391 Reader.Position = Pos;
407 using (FileStream fs = File.OpenRead(FileName))
421 using (MemoryStream ms =
new MemoryStream(Image))
437 if (Image.ReadByte() != 0xff)
440 if (Image.ReadByte() != 0xd8)
447 if (!TryReadWord(Image, out ushort TagID))
450 if (!TryReadWord(Image, out ushort Len) || Len < 2)
460 if (Image.TryReadAll(Buf, 0, Len) != Len)
467 Image.Seek(Len, SeekOrigin.Current);
470 if (Buf is
null || Buf.Length < Len)
473 if (Image.TryReadAll(Buf, 0, Len) != Len)
482 private static bool TryReadWord(Stream Input, out ushort w)
484 int i = Input.ReadByte();
493 i = Input.ReadByte();
Extracts EXIF meta-data from images.
static bool TryExtractFromJPeg(Stream Image, out ExifTag[] Tags)
Tries to extract EXIF meta-data from a JPEG stream.
static bool TryParse(byte[] ExifData, out ExifTag[] Tags)
Tries to parse EXIF data.
static bool TryExtractFromJPeg(byte[] Image, out ExifTag[] Tags)
Tries to extract EXIF meta-data from a JPEG image.
static bool TryExtractFromJPeg(string FileName, out ExifTag[] Tags)
Tries to extract EXIF meta-data from a JPEG image.
Class for ASCII-valued EXIF meta-data tags.
uint? NextLONG()
Gets next LONG (unsigned int). If no more bytes are available, null is returned.
int Position
Current position
string NextASCIIString()
Gets the next ASCII string.
int NextByte()
Gets next byte. If no more bytes are available, -1 is returned.
int Length
Length of data block
int NextSHORT()
Gets next SHORT (unsigned short). If no more bytes are available, -1 is returned.
Abstract base class for EXIF meta-data tags.
Base class for typed EXIF meta-data tags.
Represents an EXIF RATIONAL value.
Represents an EXIF SRATIONAL value.
A chunked list is a linked list of chunks of objects of type T .
void Add(T Item)
Adds an item to the collection.
T[] ToArray()
Returns an array containing all elements of the collection.
ExifTagName
Defined EXIF Tag names
ExifTagType
Data types of meta-data tags