B4J Question load image and put it into imageview?

LWGShane

Well-Known Member
Licensed User
Longtime 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
Longtime 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:
Upvote 0

LWGShane

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

LWGShane

Well-Known Member
Licensed User
Longtime 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:
Upvote 0
Top