B4J Question Load ImageView via code

SueHale

Member
Licensed User
Longtime User
I have an ImageView set up within designer but struggling to find the correct syntax to load graphic files via code. All the graphics files I wish to use are stored within the files directly.

Have tried various combinations of code, but having no luck on this simple problem!

Thank-you for any insight you can provide.

Regards
Sue.
 

rwblinn

Well-Known Member
Licensed User
Longtime User
Hi,

Various options to load an image in an imageview.
The imageview is defined in a project fxml file.

-Load an Image from the DirAssets folder
* Copy the imagefile to the DirAssets folder. This is the Files folder.
* Add the imagefile to the IDE files list. Via the Files tab.
* Note: If this is omitted, a runtime error "File not found" occurs.
* Load the image into the imageview:
B4X:
imageview1.SetImage(fx.LoadImage(File.DirAssets, "myimage.png"))

-Load an Image from the DirApp folder
* Copy the imagefile to the DirApp folder. This is the Objects folder.
* Load the image into the imageview:
B4X:
imageview1.SetImage(fx.LoadImage(File.DirApp, "myimage.png"))

-Load an Image from any other Folder
* Load the image into the imageview:
B4X:
imageview1.SetImage(fx.LoadImage("<folder path>", "myimage.png"))

Probably more ways...
 
Upvote 0

SueHale

Member
Licensed User
Longtime User
Hi Rob,

Many thanks for helping out. I knew would be kicking myself I could just not see the fx. part of the required syntax. Your answer of course worked perfectly. Also congratulations on your B4J Howto web project, much valued information and tips.

Regards
Sue.
 
Upvote 0
Top