Image in raw image(canvas)

I have this code that searches the path of an image and saves it in background.
How can I assign the path of the image to the raw image of the canvas

private void LoadBgImage() {
        string RuteBackground = Application.dataPath + "/StreamingAssets/ImgBackground";

        string[] files = Directory.GetFiles(RuteBackground);
        string background = files.FirstOrDefault(s => s.EndsWith(".jpg") || s.EndsWith(".png"));
        Debug.Log(background);
     

    }

For something like that, you’ll probably have to use a www call to load the image up and then convert it

Looks like rawimage takes a texture, so you can use the texture directly. An image uses a sprite, so you’d have to convert the texture to a sprite if you went that route.

And note, even though the www call ask for a url, you just replace that with your file location. It will load stuff from a folder or the internet.

In addition to what @Brathnann said, you should use Application.streamingAssetsPath instead of putting the path together yourself - that path might be in different places on different platforms.