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
steffani
Prole
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
AuahDark
Prole
Posts: 47
Joined: Mon Oct 23, 2017 2:34 pm
Location: Indonesia
Contact:

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 love.graphics.newImage to get a drawable image.
Profile. I don't always online in forum, so Discord is preferred. Am I LÖVE for Android dev or not? Only you can tell.

Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests