11-19-2021 09:11 AM
Hello,
Currently studying for a Professional Degree in Mechatronics and Robotics in France,
I have just discovered the CVI Labwindows software, during my training, I have to carry out a project.
I am asked to create a screenshot function and I have to save to a file, the photo will be named with a date and time at the time of the screenshot (Example "19/11 / 2021_15: 54.png").
So far I have succeeded with the SaveBitmapToFile function, but I do not know what to name the photo with date and time
error = SaveBitmapToFile ("c: \\ Users \\ jack \\ Desktop \\ screenshot \\ capture.png", cviBitmap);
I thank you in advance.
Regards.
Tim
Solved! Go to Solution.
11-19-2021 09:25 AM - edited 11-19-2021 09:30 AM
You can't give that name to your file: both slash and colon are not allowed in file names! (see this useful discussion on that)
What you can do is to use strftime () in Ansi C library to obtain a string representation of a given date and time with separators allowed in file names. You can search for function reference in every C manual at your choice.
12-13-2021 02:16 AM
Hello,
is it possible to give me an example with strftime () and file name? to understand functions, because I just discovered this program
thanks
12-13-2021 02:25 AM
Hello,
is it possible to give me an example with DateStr() in file name? to understand functions, because I just discovered this program
12-13-2021 02:40 AM
It's not difficult: DateStr () returns a string so sprintf ("%s.tst", DateStr ()); will return a correct filename.
CVI is a standard C-language programming environment: if you are new to C language you should take some time to learn the language before approaching the IDE. Or at least be sure to keep a C reference manual at hand as long as you go on developing your app. And this board cannot replace that manual!
12-17-2021 07:07 AM
Hello, I just succeeded !
#define DATETIME_FORMAT « %Y_%m_%d-%H_%M_%S »
#define CHARSIZE 256
Char filename [CHARSIZE] ;
Double datetime : 0.0 ;
Int ret = GetCurretDateTime(&datetime) ;
Char datetimeStr[CHARSIZE] ;
Int len = FormatDateTimeString(datetime, DATETIME_FORMAT, datetimeStr, CHARSIZE) ;
Fmt (filename, « C:\\Users\\........\\%s.png », datetimeStr) ;
SaveBitmapToFile (filename, image);