B4J Question How do I add and replace various images to my UI?

wdegler

Active Member
Licensed User
Longtime User
I have searched much but not found how to add an image to my UI. Hints include lines like
TabImage.Initialize(File.DirAssets,"G1.jpg")

TabImageView.Initialize("")

TabImageView.GetImage

TabImageView.SetImage(fx.LoadImage(File.DirAssets,"G1.jpg"))

along with a Scenebuilder ImageView with the ID TabImageView.
No errors show during compilation or execution but no image shows either.
I need to show an image and replace it periodically during execution. Can someone tell me how?

Walter Danny Degler
 

wdegler

Active Member
Licensed User
Longtime User
I have searched much but not found how to add an image to my UI. Hints include lines like
TabImage.Initialize(File.DirAssets,"G1.jpg")

TabImageView.Initialize("")

TabImageView.GetImage

TabImageView.SetImage(fx.LoadImage(File.DirAssets,"G1.jpg"))

along with a Scenebuilder ImageView with the ID TabImageView.
No errors show during compilation or execution but no image shows either.
I need to show an image and replace it periodically during execution. Can someone tell me how?

Walter Danny Degler
Oh, I forgot to mention that these lines are also in my code:
dim TabImage as Image
dim TabImageView as ImageView

Walter Danny Degler
 
Upvote 0

wdegler

Active Member
Licensed User
Longtime User
Oh, I forgot to mention that these lines are also in my code:
dim TabImage as Image
dim TabImageView as ImageView

Walter Danny Degler
Also, G.jpg is in my Files directory and in my File tabs list.

Walter Danny Degler
 
Upvote 0

rwblinn

Well-Known Member
Licensed User
Longtime User
Hi Walter,

pls find here under Image some examples:

B4X:
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:
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:
imageview1.SetImage(fx.LoadImage(File.DirApp, "myimage.png"))

-Load an Image from other Folder
* Load the image into the imageview:
imageview1.SetImage(fx.LoadImage("c:\Daten\bitsound\OpenIconLib\icons\png\22x22\actions\", "myimage.png"))
 
Upvote 0

wdegler

Active Member
Licensed User
Longtime User
Hi Walter,

pls find here under Image some examples:

B4X:
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:
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:
imageview1.SetImage(fx.LoadImage(File.DirApp, "myimage.png"))

-Load an Image from other Folder
* Load the image into the imageview:
imageview1.SetImage(fx.LoadImage("c:\Daten\bitsound\OpenIconLib\icons\png\22x22\actions\", "myimage.png"))
Thanki you. I appreciate your response. I had seen the site you refer to already; that is where I found that
TabImageView.SetImage(fx.LoadImage(File.DirAssets,"G1.jpg")) is needed (as in my thread above). My problem seems to have been in using type 'Image' in addition, and having size problems in SceneBbuilder for ImageView relative to my Image. With size adjustments, it seems to be working now. You showed that I was on the right track; thank you.

Walter Danny Degler
 
Upvote 0
Top