如何设置和获取 fipTag 的值
How to set and get value of fipTag
我的尝试:
fipTag t;
t.setType(FIDT_LONG);
t.setKey("FrameTime");
long l = 128;
t.setValue(&l);
据说这会将标签值设置为 128 长
然而..
const long * lo = static_cast<const long*> ( t.getValue() );
cout << "t.getValue() " << *lo << " ?? doesn't look right" << endl; // 847909360
cout << "l == *lo " << (l == *lo) << endl; // false
怎么了?我们如何在FreeImagePlus中正确设置和获取一个fipTag的值?
无用的文档:http://freeimage.sourceforge.net/fip/classfipTag.html#a34b0b079bc222aaf4b4d1ad4ce423f82
全部代码:
#include <FreeImagePlus.h>
#include <iostream>
using namespace std;
int main(void)
{
fipTag t;
t.setType(FIDT_LONG);
t.setKey("FrameTime");
long l = 128;
t.setValue(&l);
const long * lo = static_cast<const long*> ( t.getValue() );
cout << "t.getValue() " << *lo << " ?? doesn't look right" << endl;
cout << "l == *lo " << (l == *lo) << endl;
return 0;
}
当类型设置为 FIDT_LONG
时,setTag
(它只是 FreeImage_SetTagValue
的包装器)需要一个 4 字节(32 位)无符号整数数组。 long
在 64 位系统上通常是 8 个字节。
此外,必须显式设置值的总字节大小及其包含的元素数量。
#include <iostream>
#include <iterator> // std::size (C++17 or newer)
#include <FreeImagePlus.h>
int main()
{
const uint32_t writeValue[] {123, 456};
fipTag t;
t.setKey("FrameTime");
t.setType(FIDT_LONG);
t.setCount(std::size(writeValue)); // number of elements in the array
t.setLength(sizeof(writeValue)); // size of the entire array
// length must be count * expected size for FIDT_LONG (4)
if(t.setValue(writeValue)) {
auto readValue = static_cast<const uint32_t *>(t.getValue());
std::cout << "t.getValue() " << readValue[0] << std::endl;
}
return 0;
}
我的尝试:
fipTag t;
t.setType(FIDT_LONG);
t.setKey("FrameTime");
long l = 128;
t.setValue(&l);
据说这会将标签值设置为 128 长
然而..
const long * lo = static_cast<const long*> ( t.getValue() );
cout << "t.getValue() " << *lo << " ?? doesn't look right" << endl; // 847909360
cout << "l == *lo " << (l == *lo) << endl; // false
怎么了?我们如何在FreeImagePlus中正确设置和获取一个fipTag的值?
无用的文档:http://freeimage.sourceforge.net/fip/classfipTag.html#a34b0b079bc222aaf4b4d1ad4ce423f82
全部代码:
#include <FreeImagePlus.h>
#include <iostream>
using namespace std;
int main(void)
{
fipTag t;
t.setType(FIDT_LONG);
t.setKey("FrameTime");
long l = 128;
t.setValue(&l);
const long * lo = static_cast<const long*> ( t.getValue() );
cout << "t.getValue() " << *lo << " ?? doesn't look right" << endl;
cout << "l == *lo " << (l == *lo) << endl;
return 0;
}
当类型设置为 FIDT_LONG
时,setTag
(它只是 FreeImage_SetTagValue
的包装器)需要一个 4 字节(32 位)无符号整数数组。 long
在 64 位系统上通常是 8 个字节。
此外,必须显式设置值的总字节大小及其包含的元素数量。
#include <iostream>
#include <iterator> // std::size (C++17 or newer)
#include <FreeImagePlus.h>
int main()
{
const uint32_t writeValue[] {123, 456};
fipTag t;
t.setKey("FrameTime");
t.setType(FIDT_LONG);
t.setCount(std::size(writeValue)); // number of elements in the array
t.setLength(sizeof(writeValue)); // size of the entire array
// length must be count * expected size for FIDT_LONG (4)
if(t.setValue(writeValue)) {
auto readValue = static_cast<const uint32_t *>(t.getValue());
std::cout << "t.getValue() " << readValue[0] << std::endl;
}
return 0;
}