Saving Canvas to Internal Storage

im still getting 2 images saved with this block sir.

Remove the Image.Picture block.

1 Like

with different timestamps
You are saving the canvas 3 times...what about saving the canvas and refeeshing the gallery only once? Then use the path to the file and display it as image, in the label and as background image

Taifun

1 Like

with this it's still saving 2 images. i dont understand the logic behind this. i thought that with this block it will only save the final canvas with drawtext.

Each time you use the Canvas.SaveAs method you save the canvas

Save it only once and to display the background inage use the path to the image from Label1.Text

Taifun

1 Like


with this blocks it still save 2 images.. i think the afterpicture event automatically save the image before being used in the canvas. can we avoid that sir?

yes, of course if you take a picture then this also will be stored
you have 2 options:

  1. use the same filename to overwrite the already taken picture with Canvas.SaveAs
  2. delete the picture, which was taken by the camera using the file component

Taifun

1 Like

how to do the both sir? i want to learn so i can use in the future projects. my thinking is that the camera afterpicture saves it on its own and i did not commanded it to save as as my own naming.

If you want to try option 1

then store the image from the AfterPicture event in a global variable and use that to later save the canvas

Fir option 2

Try the Delete method from the file component together with the inage from the AfterPicture event

A very good way to learn App Inventor is to read the free Inventor's Manual here in the AI2 free online eBook App Inventor 2 Book: Create Your Own Android Apps ... the links are at the bottom of the Web page. The book 'teaches' users how to program with AI2 blocks.
There is a free programming course here Course In A Box and the aia files for the projects in the book are here: App Inventor 2 Book: Create Your Own Android Apps
How to do a lot of basic things with App Inventor are described here: How do you...? .

Also do the tutorials Our Tutorials! to learn the basics of App Inventor, then try something and follow the Top 5 Tips: How to learn App Inventor

Taifun


Trying to push the limits! Snippets, Tutorials and Extensions from Pura Vida Apps by icon24 Taifun.

1 Like


sir, i am trying to delete the camera image but it doesnt work. is it really possible to delete it ?

Yes, but the File component needs/uses a relative path (not an absolute or full path).


Note:
If you try to use the File.Exists method, you'll find that READ permissions (on Android 13+ all storage permissions: AUDIO, VIDEO, IMAGES) are incorrectly requested (on Android 11+). In this case, use my MFile extension instead. @ewpatton


1 Like

thank you so much sir!! it worked !

Does the permission issue continue to be a problem on ai2-test for you?

Yes.

I also noticed that Canvas.BackgroundImage does not request READ permission, but Image.Picture does (incorrectly). Also File.Delete does not work either with FileScope=Share or Legacy. (Tested on Android 16 on main & test server.)


As I've said many, many times, please remove all automatic storage permission requests. These are only required for older Android versions (≤ 10) anyway, and starting in May 2025, they may only be requested for audio files. These idiotic "user-friendly" permissions have been driving me crazy for almost a decade and a half and it's getting worse every year.

If you want to publish an app on the Play Store, the only option regarding storage permissions is to request READ permission for audio files (at least for newer Android versions).

In this respect, it makes sense to remove all storage permission requests (at least for newer Android versions). It should be common knowledge by now that storage permissions are required on Android < 11 and this is generally done by only requesting WRITE permission, as this also implicitly grants READ permission.

Maintaining automatic storage permission requests leads to uncertainty, confusion, and frustration not only for "normal" users/app developers, but also for power users.

1 Like