Update rational value for exif tag

Jul 15, 2015 at 11:47 AM
Hello
I need to update a rational value for exif tag and save the updated value to file.

I'm trying to use following code but it works incorrectly:
using (MagickImage image = new MagickImage(SampleFiles.FujiFilmFinePixS1ProJpg))
{
    ExifProfile profile = image.GetExifProfile();

    double exposureTimeValue = 1 / (double)1600;

    profile.SetValue(ExifTag.ExposureTime, exposureTimeValue);
    image.AddProfile(profile);

    image.Write(SampleFiles.OutputDirectory + "FujiFilmFinePixS1Pro.updatedExif.jpg");
}
I checked the value, which was saved in the exif profile and it is not equal to the value which I saved:
using (MagickImage image = new MagickImage(SampleFiles.FujiFilmFinePixS1ProJpg))
{
    ExifProfile profile = image.GetExifProfile();

    double exposureTimeValue = 1 / (double)1600;
    // 0.000625

    profile.SetValue(ExifTag.ExposureTime, exposureTimeValue);
    image.AddProfile(profile);

    double savedExposureTimeValue = (double)image.GetExifProfile().Values.First(item => item.Tag == ExifTag.ExposureTime).Value;
    // 0.00062578222778473093

    image.Write(SampleFiles.OutputDirectory + "FujiFilmFinePixS1Pro.updatedExif.jpg");
}
How can I update rational(signed rational) value in a exif profile?
Coordinator
Jul 15, 2015 at 3:50 PM
Edited Jul 15, 2015 at 4:16 PM
Rational values are stored as a fraction. And the current calculation was not as precise as possible. I have modified the calculation to make it more precise. I just created a unit test with the value from your example and it passes without a problem. The only down side to this is that it will decrease the performance of the application because the value is calculated. And that is why I have added a new boolean to disable this behavior to the ExifProfile class.

EDIT: I did some more tests and it has quite an impact on the performance so I will set the option to disabled by default for now. I might change this later if I have a quicker calculation. You can enable it with the BestPrecision property in the next release.
Jul 16, 2015 at 7:04 AM
Dirk,
How soon are going to push out the next release?
Have you committed these changes to the repository?
Coordinator
Jul 16, 2015 at 7:11 AM
I will try to publish a new release this weekend. And I will push my changes later today.
Jul 16, 2015 at 7:14 AM
Good news! Thanks.