LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

(Request help for a project) Save a photo with a date and time

Solved!
Go to solution

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

0 Kudos
Message 1 of 6
(2,411 Views)

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.



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 2 of 6
(2,403 Views)

Hello,
is it possible to give me an example with strftime () and file name? to understand functions, because I just discovered this program

thanks

0 Kudos
Message 3 of 6
(2,198 Views)

Hello,
is it possible to give me an example with DateStr() in file name? to understand functions, because I just discovered this program

0 Kudos
Message 4 of 6
(2,220 Views)
Solution
Accepted by topic author TimStudent50

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!



Proud to use LW/CVI from 3.1 on.

My contributions to the Developer Community
________________________________________
If I have helped you, why not giving me a kudos?
Message 5 of 6
(2,209 Views)
Solution
Accepted by topic author TimStudent50

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);

0 Kudos
Message 6 of 6
(2,137 Views)