Saving more than one Canvas image

For my project, I'm reading some data via BLE, which then I plot on a canvas. This action can be repeated multiple times as: read data -> plot -> clear graph -> read more data -> plot again

I want to be able to save the images each time I plot the data.

However, whenever I save the graph, it overwrites the one already saved in my phone's storage.

Does anyone know if it's posible to save more than one image?

Thanks in advance!

Update: Changing the filename worked!

Do you use Canvas.Save?
Use Canvas.SaveAs instead and modify the filename each time, like image1.jpg, image2.jpg,...


Tip:
For unique filename each time, you may join the timestamp with the filename, like image2021_03_04_235959.jgp


Hope it helps :blush:

1 Like

Oh, that's good advice! That makes sense.

I was already using Canvas.SaveAs, but the filename was just a text box I created in Blocks. I just asumed that when new files were added, the names would be "filename(1).jpg", "filename(2).jpg," etc.

But I guess it was just overwriting the previous file.

I don't know how to get the timestamp automatically, but I added a text box in the app so the user can name the file. I'll try to see if that works.

Thank you!

Use the Clock.FormatDateTime to create timestamp and join it with thr filename using the Text.Join block.

See how to use the block...

FormatDateTime( instant , pattern )
Converts and formats an instant into a string of date and time with the specified pattern. To learn more about valid patterns, please see SimpleDateFormat. Acceptable patterns are empty string, MM/dd/YYYY HH:mm:ss a , or MMM d, yyyy HH:mm . The empty string will provide the default format, which is "MMM d, yyyy HH:mm:ss a" for FormatDateTime , "MMM d, yyyy" for FormatDate . To see all possible formats, please see here.

Hope it helps :blush:

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.