Get image from gallery in android?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Posts: 1
Joined: Tue Feb 04, 2020 9:03 am

Get image from gallery in android?

Post by steffani » Tue Feb 04, 2020 9:16 am

I want to know if there's a way I can request to get an image from love2d out of the gallery in android. I say android because I don't think it would be cross compatible, but if it is then that's also good. My idea is just to select an image as you do in many apps, and load it into love2d in a drawable format. If the image can be selected, I doubt it will be drawable straight away.

User avatar
Posts: 76
Joined: Mon Oct 23, 2017 2:34 pm
Location: Indonesia

Re: Get image from gallery in android?

Post by AuahDark » Sat Feb 15, 2020 2:09 pm

Not sure if this is possible with plain Lua. You always have to interact with Java code, but here's the overall steps

1. Write code which loads default image picker (usually gallery, provided by system in recent OS) and return its contents.
2. Write a JNI bridge for that function.
3. Write a Lua binding for that function. If you know how to create LOVE Data object, prefer that. Otherwise, just return it as plain string.
4. Call it from LOVE code, and if you return raw string instead of LOVE Data object, use love.filesystem.newFileData(contents, "").
5. Once you have the Data object, simply pass that data object to first argument of to get a drawable image.
Profile. Do you encounter crashes in LÖVE Android and wanna send me logcats? Please hit me up in Discord and send the full logcat file!

Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 56 guests