[英]Modifying the date and time values using SYSTEMTIME, FILETIME, and ULARGE_INTEGER
I am making a program, in C++ using Visual Studio 2005, that needs to create a watermark with the time on a set of images. 我正在使用Visual Studio 2005在C ++中创建一个程序,它需要在一组图像上创建带有时间的水印。
These images are taken from a video that were processed at certain time intervals. 这些图像来自以特定时间间隔处理的视频。 What I am trying to do is to modify the time on each image through SYSTEMTIME.
我想要做的是通过SYSTEMTIME修改每个图像的时间。 I looked at the MSDN and it says not to modify the values within SYSTEMTIME itself, but to convert it into a FILETIME and then an ULARGE_INTEGER.
我查看了MSDN,它说不修改SYSTEMTIME本身的值,而是将其转换为FILETIME,然后转换为ULARGE_INTEGER。 My question is how is the ULARGE_INTEGER split up?
我的问题是ULARGE_INTEGER是如何拆分的? Is the HighPart the date and the Low Part the time and if that's the case how to I take into account rollover?
HighPart是日期,Low Part是时间,如果是这样,我如何考虑翻转? Like if a image shows up at 11:58pm on 2/25/2011 and goes through until 12:11 2/26/2011?
比如图像出现在2011年2月25日晚上11:58并持续到2011年2月26日12:11? Would just adding the specified value automatically be taken into account and shown when I convert it back into a SYSTEMTIME variable?
只是添加指定的值会被自动考虑并在我将其转换回SYSTEMTIME变量时显示吗?
Thanks in advance for your help. 在此先感谢您的帮助。
They suggest converting SYSTEMTIME
to FILETIME
, which is a number of ticks since an epoch. 他们建议将
SYSTEMTIME
转换为FILETIME
,这是一个时代以来的许多刻度。 You can then add the required number of 'ticks' (ie 100ns intervals) to indicate your time, and convert back to SYSTEMTIME
. 然后,您可以添加所需数量的“滴答”(即100ns间隔)来指示您的时间,然后转换回
SYSTEMTIME
。
The ULARGE_INTEGER
struct is a union with a QuadPart
member, which is a 64bit number, that can be directly added to (on recent hardware). ULARGE_INTEGER
结构是一个带有QuadPart
成员的联合,它是一个64位数字,可以直接添加到(在最近的硬件上)。
SYSTEMTIME add( SYSTEMTIME s, double seconds ) {
FILETIME f;
SystemTimeToFileTime( &s, &f );
ULARGE_INTEGER u ;
memcpy( &u , &f , sizeof( u ) );
const double c_dSecondsPer100nsInterval = 100.*1.e-9;
const double c_dNumberOf100nsIntervals =
seconds / c_dSecondsPer100nsInterval;
// note: you may want to round the number of intervals.
u.QuadPart += c_dNumberOf100nsIntervals;
memcpy( &f, &u, sizeof( f ) );
FileTimeToSystemTime( &f, &s );
return s;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.