2using System.Collections.Generic;
17 private static readonly Dictionary<int, ExifTagName> names = GetNames();
19 private static Dictionary<int, ExifTagName> GetNames()
21 Dictionary<int, ExifTagName> Names =
new Dictionary<int, ExifTagName>();
24 Names[(int)Value] = Value;
38 List<ExifTag> List =
new List<ExifTag>();
57 Reader.BigEndian =
false;
61 Reader.BigEndian =
true;
76 int Pos = RefPos + (int)Offset.Value;
77 if (Pos < Reader.Position || Pos >= Reader.
Length)
80 Reader.Position = Pos;
94 if (!names.TryGetValue(TagID, out
ExifTagName Name))
106 int NrElements = (int)Count.Value;
136 int RecSize = (int)(Count.Value * ElementSize);
141 PosBak = Reader.Position + 4;
144 uint? ValueOffset = Reader.
NextLONG();
145 if (!ValueOffset.HasValue || RefPos + ValueOffset.Value > Reader.
Length)
149 Reader.Position = RefPos + (int)ValueOffset.Value;
165 byte[] Items =
new byte[NrElements];
167 for (j = 0; j < NrElements; j++)
196 ushort[] Items =
new ushort[NrElements];
198 for (j = 0; j < NrElements; j++)
204 Items[j] = (ushort)i;
207 List.Add(
new ExifTypedTag<ushort[]>(TagID, Name, Items));
224 uint[] Items =
new uint[NrElements];
226 for (j = 0; j < NrElements; j++)
246 uint NumeratorValue = u.Value;
252 uint DenominatorValue = u.Value;
259 for (j = 0; j < NrElements; j++)
265 uint NumeratorValue = u.Value;
271 uint DenominatorValue = u.Value;
273 Items[j] =
new Rational(NumeratorValue, DenominatorValue);
291 byte[] Items =
new byte[NrElements];
293 for (j = 0; j < NrElements; j++)
317 int[] Items =
new int[NrElements];
319 for (j = 0; j < NrElements; j++)
325 Items[j] = (int)u.Value;
339 int NumeratorValue = (int)u.Value;
345 int DenominatorValue = (int)u.Value;
352 for (j = 0; j < NrElements; j++)
358 int NumeratorValue = (int)u.Value;
364 int DenominatorValue = (int)u.Value;
374 Reader.Position = PosBak;
380 if (!Offset.HasValue)
383 if (Offset.Value == 0)
386 Pos = RefPos + (int)Offset.Value;
387 if (Pos < Reader.Position || Pos >= Reader.
Length)
390 Reader.Position = Pos;
394 Tags = List.ToArray();
406 using (FileStream fs = File.OpenRead(FileName))
420 using (MemoryStream ms =
new MemoryStream(Image))
436 if (Image.ReadByte() != 0xff)
439 if (Image.ReadByte() != 0xd8)
446 if (!TryReadWord(Image, out ushort TagID))
449 if (!TryReadWord(Image, out ushort Len) || Len < 2)
459 if (Image.TryReadAll(Buf, 0, Len) != Len)
466 Image.Seek(Len, SeekOrigin.Current);
469 if (Buf is
null || Buf.Length < Len)
472 if (Image.TryReadAll(Buf, 0, Len) != Len)
481 private static bool TryReadWord(Stream Input, out ushort w)
483 int i = Input.ReadByte();
492 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.
ExifTagName
Defined EXIF Tag names
ExifTagType
Data types of meta-data tags