How to set real value?
Added by Mikayel Egibyan over 6 years ago
What can I use to set real values like FNumber?
This gives an operator=
error.
exifData["Exif.Photo.FNumber"] = 1.2;
image->writeMetadata();
Thanks!
Replies (4)
RE: How to set real value? - Added by Robin Mills over 6 years ago
Mikayel
Exif doesn't define a floating point value equivalent to "C" float or double data type. When you look in the standard, you'll find Exif.Photo.Number is defined as RATIONAL which is a ratio of two integers. In your case: 12 / 10.
We discussed the standard and types in an earlier discussion: http://dev.exiv2.org/boards/3/topics/1892?r=1894#message-1894
You'll see in use in this sample http://exiv2.org/example2.html
exifData["Exif.Image.YResolution"] = Exiv2::Rational(-2, 3); // RationalValueHere's a photo I took recently:
C:\cygwin64\home\rmills\gnu\exiv2\video-write\msvc2005\bin\x64\debugdll>exiv2 -pa -g FNumber \R.jpg Exif.Photo.FNumber Rational 1 F7.1I've modified exifprint.cpp as follows:
int main(int argc, char* const argv[]) try { if (argc != 2) { std::cout << "Usage: " << argv[0] << " file\n"; return 1; } Exiv2::Image::AutoPtr image = Exiv2::ImageFactory::open(argv[1]); assert(image.get() != 0); image->readMetadata(); Exiv2::ExifData &exifData = image->exifData(); // exifData["Exif.Photo.FNumber"] = Exiv2::Rational(12,10); exifData["Exif.Photo.FNumber"] = Exiv2::floatToRationalCast(1.2f); image->writeMetadata(); return 0; }Rebuilt exifprint.exe and ran it. Then inspected the FNumber:
C:\cygwin64\home\rmills\gnu\exiv2\video-write\msvc2005\bin\x64\debugdll>exifprint.exe \R.jpg C:\cygwin64\home\rmills\gnu\exiv2\video-write\msvc2005\bin\x64\debugdll>exiv2 -pa -g FNumber \R.jpg Exif.Photo.FNumber SRational 1 F1.2 C:\cygwin64\home\rmills\gnu\exiv2\video-write\msvc2005\bin\x64\debugdllHappiness (Almost). I'm a little surprised that it displays SRational (for Signed Rational). Something for you to investigate.
RE: How to set real value? - Added by Mikayel Egibyan over 6 years ago
I see, thanks!
Does it have any built in function to revert 1.5 to 3/2 ?
Thanks.
RE: How to set real value? - Added by Robin Mills over 6 years ago
Can you post your solution please?
The spirit of open-source is to share intellectual property. One day your fix could help another user and save everybody time.