B4J Question load image and put it into imageview?

ShaneG30

Well-Known Member
Licensed User
I'm kinda confused on how to load an Image via a File Chooser and then insert the resulting image into an ImageView.

Thanks.
 

jmon

Well-Known Member
Licensed User
It's simple:
B4X:
Dim SelectImg As FileChooser
SelectImg.Initialize   
SelectImg.SetExtensionFilter("Image", "*.jpg")
SelectImg.Title = "Change your photo"
FileImg = SelectImg.ShowOpen(Main.MainForm)

If FileImg <> "" Then
    iv.SetImage(fx.LoadImageSample(File.GetFileParent(FileImg), File.GetName(FileImg), iv.Width, iv.Height))
    'or
    iv.SetImage(fx.LoadImage(File.GetFileParent(FileImg), File.GetName(FileImg))
end if
[edit] missnamed the second LoadImage to LoadImageSample
 
Last edited:

ShaneG30

Well-Known Member
Licensed User
@jmon - Awesome, it works!
 

ShaneG30

Well-Known Member
Licensed User
Sorry I forgot to say that FileImg should be declared as string.
I figured that out ;) It was kinda obvious when FileImg was used to see if a file path existed. Paths are strings, so.....
 
Last edited:
Top