Home Image-Pro Plus Automation with Macros

How to modify the code of "time stamp"

(Originally posted by dewrosy on 12/7/2006)

I got the code of "FrameTime"from--- http://www.mediacy.com/index.aspx?page=ViewSolution&solid=1151
Q1: The problem is :
The type of display model is "12/07/2006 02:52:10.626PM"
This time is too precise. I like the display is "02:52:10.626". How to get rid of the "12/07/2006" and "PM" from modifing the code?
Q2: Text for displaying the time is frozen, I want to move it in the movie! Because the pisotoin will not good for displaying! How to do it? Thank you very much!



The code is:
' Default Script
Option Explicit

'**********************************************************************
' Filename: FrameTime.scr
' Copyright Media Cybernetics, Inc. 2004
'
' Free for use as demonstration code.
'
'----------------------------------------------------------------------
' PROBLEM SOLVED:
'
' Output the frame times from a sequence.
'
' The second macro burns the frame times into the sequence as
' text, which permanently alters the images, but is a good illustration
' of how to use the HilImControl functions to get the times.
'----------------------------------------------------------------------
' WHO WOULD USE THIS:
'
' Users and programmers wishing to extract frame times for various
' reasons. This code can be used as a basis for annotating images, for
' tracking purposes, etc.
'----------------------------------------------------------------------
' SYSTEM REQUIREMENTS:
'
' Image-Pro or derived products 4.x or later
'----------------------------------------------------------------------
'HISTORY OF CHANGES:
'Macro Version: 1.0
'Created: 1/30/04
'Modified: 1/30/04
'Author: KR
'Application: IPWin
'Version: 4.x
'Change History:
' 1.0: 1/30/04 KR Created
'**********************************************************************

' Commands for obtaining data from the images
Declare Function HilImControl Lib "HILIMG32" (ByVal ihImage As Long, _
ByVal icCommand As Long, ByVal sParam As Integer, ByVal lParam As Long, _
pParam As Any) As Long

Declare Function HilImControlStr Lib "HILIMG32" Alias "HilImControl" (ByVal ihImage As Long, _
ByVal icCommand As Long, ByVal sParam As Integer, ByVal lParam As Long, _
ByVal pParam$) As Long

' Date structures
Type FILETIME ' Seconds since January 1, 1601
dwLowDateTime As Long
dwHighDateTime As Long
End Type

Type SYSTEMTIME ' Date converted into individual values
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type

' Convert a FILETIME into a SYSTEMTIME
Declare Function FileTimeToSystemTime Lib "Kernel32" (pFtime As Any, pSystem As Any) As Boolean

' Constants for obtaining the time from the image
Const IMCMD_GETFRAMEDATE = 66
Const IDT_LOCALSTR = 0 ' original Format String In local Time
Const IDT_GMTSTR = 1 ' original Format String In GMT Time
Const IDT_LOCALFILETIME = 2 ' local Time In FILETIME structure (For calculation)
Const IDT_GMTFILETIME = 3 ' GMT Time In FILETIME structure (For calculation)

' Loop through the frames of the sequence, output frame times both as a string
' and as individual numbers.
Sub GetFrameTimes()
Dim timeStr As String*255
Dim frameDate As Date, frameDate1 As Date
Dim i As Integer, nFrames As Integer
Dim sVRI As Integer, targetVRI As Long
Dim fTime As FILETIME
Dim sTime As SYSTEMTIME
Dim strDay(0 To 6) As Variant

strDay(0) = "Sun"
strDay(1) = "Mon"
strDay(2) = "Tue"
strDay(3) = "Wed"
strDay(4) = "Thr"
strDay(5) = "Fri"
strDay(6) = "Sat"

ret = IpSeqGet( SEQ_NUMFRAMES, nFrames )
For i=0 To nFrames-1
ret = IpSeqSet( SEQ_ACTIVEFRAME, i )
IpDocGet(GETDOCVRI, DOCSEL_ACTIVE, sVRI)
targetVRI = sVRI

' Obtain time as a formated string
HilImControlStr(targetVRI, IMCMD_GETFRAMEDATE, IDT_LOCALSTR, i, timeStr)

Debug.Print IpTrim(timeStr); " Or ";

' Obtain time in seconds
HilImControl(targetVRI, IMCMD_GETFRAMEDATE, IDT_LOCALFILETIME, i, fTime)
' Convert to individual fields
FileTimeToSystemTime(fTime, sTime)

Debug.Print " Year:"; sTime.wYear; " Month:"; sTime.wMonth; " Day: ";
Debug.Print strDay(sTime.wDayOfWeek); " Date:"; sTime.wDay; " Hour:"; sTime.wHour;
Debug.Print " Minute:"; sTime.wMinute; " Second:"; sTime.wSecond;
Debug.Print " Msec:"; sTime.wMilliseconds
Next i

Debug.Print ""
End Sub

' Annotate each frame with its date
Sub AnnotateFrameTimes()
Dim timeStr As String*255
Dim frameDate As Date, frameDate1 As Date
Dim i As Integer, nFrames As Integer
Dim sVRI As Integer, targetVRI As Long

ret = IpSeqGet( SEQ_NUMFRAMES, nFrames )
For i=0 To nFrames-1
ret = IpSeqSet( SEQ_ACTIVEFRAME, i )
IpDocGet(GETDOCVRI, DOCSEL_ACTIVE, sVRI)
targetVRI = sVRI

' Obtain time as a formated string
HilImControlStr(targetVRI, IMCMD_GETFRAMEDATE, IDT_LOCALSTR, i, timeStr)

' Burn in the result
ret = IpAnCreateObj(GO_OBJ_TEXT)
ret = IpAnMove(0, 30, 30)
ret = IpAnText(IpTrim(timeStr))
ret = IpAnSet(GO_ATTR_TEXTAUTOSIZE, 1)
ret = IpAnBurn()
Next i

Debug.Print ""
End Sub

 

Comments

  • edited June 2013

    (Originally posted by YuriG on 12/7/2006)

    The time is returned in timeStr, so if you want to display a short version of time string you can use Mid to get the middle part:

    timeStr=Mid(IpTrim(timeStr),12,12)

    (Check Macro help for Mid to get the details)

    The text is placed on image by the following line:
    ret = IpAnMove(0, 30, 30)
    where you can change the coordinates.

    The annotation is burned to the image by IpAnBurn(), so you can't move it. If you disable this line, the time will be a floating annotation, but annotation is a property on the image (not frame), so if you have multiple frames, all frame time strings will be overlapped, so I don't recommend you doing that.

Sign In or Register to comment.