How to simply loading an image from file to static image component

Hello folks,

I searched the forums and couldn’t find a proper solution to a rather simple question: how to load an image, from a local file into a static image component?

I stumbled into the dynamic image component but it seems too complicated. I also tried to load the image directly using the path as a text, but didn’t work (altough I checked and the file was ok).

For a reference, I am trying this code below, with no sucess at all:

Also, I made the image component (img_coords) as visible, cuz I thought maybe the “edit and save” instructions were being executed before the image is loaded, but still no image is loaded at all.

If someone cold give me a help it would be really nice, thank you.

The set image picture to block does not work ?

You mean this one below?

image

Passing the path to the component, right? Well, no, didn’t work. It was the first thing I did.

1 Like

Check your path :

and

1 Like

ok I will check the path but I am using android 8.1 (project uses API for android 8) and I was able to save a picture taken from the camera inside the folder I specified. But if anyone could post a block sucessfully loading an image into a image component from a path, i would really apretiate.

Ok guys I finally figured that out, but it took me a lot of testing and I must admit, as a fresh Kodular user, I almost gave up and go to another tool to build Android apps, cuz I tought “hell, it’s such a basic thing, why is it so hard and undocumented?”. So, I will register here the solution for those that may pass the same trouble in the future.

The key is that, for saving the file (at least using Companion) you just need to specify a “virtual” path like “/Pictures/filename.jpg” but to load it, you need to specify the whole path from the root, that in my case is “/storage/emulated/0/Pictures/filename.jpg”. Here are the blocks:

For the sake of information, I am testing using:
Companion 1.5.3 Fenix
Moto G5 Android 8.1 (Oreo)
Project using API for Android 8
Using internal storage (no SD card)

I hope this helps someone in the future. Thanks to all that contributed.

2 Likes

Hi :+1: :clap:
These solutions already exist here in the community. Including blocks that check if you are using Companion or not and also check API Version…etc

The blocks to be able to do the checks (just an example - Share Files + Taifun Extension)

Screenshot_20220215-161100~2

2 Likes

Thanks, I will look that up.

1 Like

Your effort will be rewarded, now you have the knowledge.:clap::clap::clap::+1:

2 Likes

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