[F/OS] 🖼️ ViewUtil: Convert a component into an image!

Extension is stabilized, which I like...

Anyways, nice extension!

2 Likes

Thank you all.

Hmmm...in Android API they removed and added new file types. Because of this, PNG and JPEG are the only types that support all Android versions.

2 Likes

:chocolate_bar: Version 2!

  • Updated events and added new ones.

Failed

image

This event is fired when the extension has encountered an error. Possible reasons: quality is not a number between 0 and 100, wrong path, etc.

Parameters: error = text

Saved

image

This event is fired when the extension has saved the image at the path.

Parameters: path = text

EDIT: Added to here.

3 Likes

Can you add a return block returing base64 of component image without saving it

1 Like

Good extension but still don't understand the main idea and how it can be beneficial actually , thanks for providing the aia file to understand what is doing too

Could be beneficial if you have labels in an arrangement that has weather data, and you want to export them.

3 Likes

Very useful extension. Thanks Gordon. See: https://community.appinventor.mit.edu/t/padding-adding-a-border-extending-an-image/89200

2 Likes

Hi Gordon.
I am facing an issue with this SaveComponentAsImage bloc. It works fine, Thanks a lot. But the image is certainly buffered somewhere, and if I try to read it, it fails. It is REALLY written in the file system when the application is closed.
I tried the GalleryRefresh from Taifun tools extension, but it does not help.
Is there a way to force the file to be written, and get an event when it has been written?
Thanks a lot

:question:

image

Unfortunately this event indicates that the file is saved, but I suppose, it's still in a buffer, or in a cache but not really written in the file system. It is finally written in the file system only when the app is closed.

Try viewing the file from the path provided in the event block.

If you can view the image then the file exists and is saved to the file system.

You could also test with the FileExists block from the file component.

How are you using the GalleryRefresh block ? (and can the file actually be viewed in the Gallery?)

Most probably the file is stored in ASD?
What about providing some relevant blocks so we do not have to guess?
To be able to view it in the gallery, the image has to be stored in shared storage

Taifun

Hi Taifun, yes, you are right, I store in ASD, so refresh gallery cannot be used, it was just a guess / trial I did

Regarding the problem itself, it is a little bit more complex. Actually, after save, the file exists, but it is almost empty, it is filled by the image data later / when app is closed. If I connect my phone with USB to access phone app folders, I see that the image file is created, but it is only 62 bytes, once filled with image data after a while or when app is closed, it becomes around one MB: the real image data.
Also if I try to reload the image from the saved file, I do not get the saved image, but a previous one (I assume in the memory cache)
I am going to clean my test app so I can share it with you

I do not see this behaviour. Testing with companion app, the file is saved and returned for display almost immediately.

image

It happens too quickly for the Progress Dialog to display itself!

1 Like

Thanks a lot for testing so quickly. I really appreciate.
You are right, it looks like it is working fine with a single image, and I assume that when we retrieve the image, it is in the cache, so it works
If you save an image one.png, then save an image two PNG, and then read two PNG you get one PNG
I'll work tomorrow on a clean sample app that I can share (current one is messy as I made many different trials)

I made a small test app that allows to switch between two images to be displayed in a horizontal arrangement, and a button to save this arrangement (SaveComponentAsImage) and display it.
Saving this arrangement is OK the first time, but if we switch the image, when saving I get the old image, not the new one.

Here is the app: Test_SaveComponent.aia (367.2 KB)

Any idea on what I am doing wrong?

Thanks

Hmmm, I see :wink:

Requires further investigation. It is not the other extensions (Taifun File / GetASD) the same happens without them.

It is @Gordon_Lu 's extension causing the problem, possibly this ?

view.setDrawingCacheEnabled(true);
Bitmap b = view.getDrawingCache();

Try this one instead, seems to work just fine

Thanks for the investigation.
I tried the extension you mention, but when calling ConvertToImage, I do not get the event Created and it does not work.
@TIMAI2 : Did you try it?
@Gordon_Lu : Could you have a look to that issue ?
Thanks a lot for your support