为图像添加时间戳(获取系统时间,精确到毫秒)

把时间戳加到图像的前几个像素,前三位是小时,分钟,秒,后两位是毫秒,因为毫秒是四位数

time_t t=time(NULL);
    std::chrono::time_point<std::chrono::system_clock, std::chrono::milliseconds> tp = std::chrono::time_point_cast<std::chrono::milliseconds>(std::chrono::system_clock::now());
    auto tmp = std::chrono::duration_cast<std::chrono::milliseconds>(tp.time_since_epoch());
    std::time_t timestamp = tmp.count();
    std::time_t milli = timestamp;
    int MS = milli % 1000;

    char H[3], M[3], S[3];
    memset(H, 0, 3);
    memset(M, 0, 3);
    memset(S, 0, 3);
    strftime(H, sizeof(H), "%H", localtime(&t));
    strftime(M, sizeof(H), "%M", localtime(&t));
    strftime(S, sizeof(H), "%S", localtime(&t));


    TestImg.data[0] = atoi(H);
    TestImg.data[1] = atoi(M);
    TestImg.data[2] = atoi(S);
    TestImg.data[3] = MS / 100;
    TestImg.data[4] = MS % 100;

 

时间就是17:26:21.917

 

posted @ 2020-10-09 17:31  Wangtn  阅读(1780)  评论(0编辑  收藏  举报