goldengel / exiflibrary

Automatically exported from code.google.com/p/exiflibrary
MIT License
0 stars 0 forks source link

Exception when reading file with dates set by the camera to Unknown #36

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Open a JPG file containing dates set to unknown ("0000:00:00 00:00:00) 
(DateTime, DateTimeDigitized, DateTimeOriginal (using ImageFile.FromFile

What is the expected output? What do you see instead?
Expect the file to open correctly, with dates set to Date.MinValue
Instead: Exception: {"Year, Month, and Day parameters describe an 
un-representable DateTime."}
"   at System.DateTime.DateToTicks(Int32 year, Int32 month, Int32 day)
   at System.DateTime..ctor(Int32 year, Int32 month, Int32 day, Int32 hour, Int32 minute, Int32 second)
   at ExifLibrary.ExifBitConverter.ToDateTime(Byte[] data, Boolean hastime)
   at ExifLibrary.ExifBitConverter.ToDateTime(Byte[] data)
   at ExifLibrary.ExifPropertyFactory.Get(UInt16 tag, UInt16 type, UInt32 count, Byte[] value, ByteOrder byteOrder, IFD ifd)
   at ExifLibrary.JPEGFile.ReadExifAPP1()
   at ExifLibrary.JPEGFile..ctor(Stream stream)
   at ExifLibrary.ImageFile.FromStream(Stream stream)
   at ExifLibrary.ImageFile.FromFile(String filename)

What version of the product are you using? On what operating system?
0.16. Did not occur in previous version (dated from January, sorry not sure 
which version number)

Is this issue specific to a certain image? If so, please attach the zipped
image. IMPORTANT: Please zip the image and attach the zip file to prevent
the image being re-encoded.

Please provide any additional information below.

Original issue reported on code.google.com by fraseco on 19 Oct 2011 at 3:12

GoogleCodeExporter commented 8 years ago
I think I might have been wrong about it working in a previous version. 
Unfortunately I can't test it 

Original comment by fraseco on 19 Oct 2011 at 3:36

GoogleCodeExporter commented 8 years ago
I suggest the following change to ExifBitConverter.ToDateTime. After the line:
            string[] parts = str.Split(new char[] { ':', ' ' });
insert:
            if (int.Parse(parts[0]) + int.Parse(parts[1]) + int.Parse(parts[2]) == 0)
                //A date with each part set to zero is used on at least one camera to indicate an unknown date.
                //DateTime has no such concept, and its earliest possible date is 0001/01/01.
                //So we set the date to that value rather than let DateTime throw an exception
            {
                parts[0] = "1"; parts[1] = "1"; parts[2] = "1";
            }

Original comment by fraseco on 24 Oct 2011 at 4:08

GoogleCodeExporter commented 8 years ago
This issue was closed by revision r92.

Original comment by oozcitak on 9 Mar 2012 at 4:24