Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / How to select an image on Android without losing transparency?

Author
Message
Santiago3D
4
Years of Service
User Offline
Joined: 11th May 2020
Location: Argentina
Posted: 6th Jun 2024 00:07
Hello, I am working on an app, where the user must be able to choose a .PNG image, with transparency, and be able to use it as a logo within the app.

The problem is that on ANDROID, on the tablet, when using the "GetChoosenImage()" function I select a .png on the tablet but it loads it without transparency.

I would like to know if there is any option that from the APP on Android, I can read a file in a specific directory.
In Windows I could read a file such as eg. "C:\appruleta\logo.PNG" and so you could load a specific file.

But in android, I can't find a way to upload an image file or a file in an absolute directory.


If only I could do something like:
img_logo = loadimage("internal_memory_root\personal_logos\logo.png")

or

logo_file$ = "internal_memory_root\personal_logos\logo.png"

img_logo = loadimage(logo_file$)

Anyway, I can't make the user choose an image that they create, and use it within the APP on ANDROID.
Bogle
2
Years of Service
User Offline
Joined: 30th Apr 2022
Location:
Posted: 6th Jun 2024 04:08 Edited at: 6th Jun 2024 04:10
You can definitely use absolute file paths. See the OpenToWrite function documentation, but for android you should use img = LoadImage( "raw:/sdcard/Download/someimage.png" ) or whatever directory you want. If you want to write to an absolute path you need to give yourself write permissions with RequestPermission( "WriteExternal" ).

I just tried GetImageFilename with GetChosenImage to see if it saves the path, but it seems to be using a temporary file called "/choosenimage.jpg". That's why its losing the transparency, and there doesn't seem to be a way to prevent it from converting your png to a jpg. Interestingly the path is preserved on windows, but that doesn't help you. You also can't use ChooseRawFile on android. So you'll have to roll your own interface for this unfortunately.
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 6th Jun 2024 04:34 Edited at: 6th Jun 2024 05:52
Quote: "it seems to be using a temporary file called "/choosenimage.jpg"."

was going to report the same odd thing while i haven't tested whether or not it's actually copying the file to either read/write folder.

Quote: "That's why its losing the transparency"

i thought Santiago advised on Discord that the transparency was fine when loaded via GetChoosenImage() inside the app/as a sprite so i didn't think this is where it was losing it but re-reading and they were using LoadImage().

meanwhile might be insightful that:
GetDocumentsPath() report "/storage/emulated/0"
GetWritePath() reports "/data/user/0/packagename/files/AppName/"
while GetReadPath() = ""

...this is on broadcast so will continue poking around.

add: just exported this as APK which reports the same as broadcast:

otherwise, @Santiago, you could try SetImageTransparentColor() for the iamge then SetSpriteTransparency() and hope the jpg is lossless and replacing trans with black?

more "insight" on the Repo here and here? dunno why it wouldnt use the same filetype as the Chosen image but seems they expected only phone photos to be shared via socials or something ~10 years ago?
Scribble
7
Years of Service
User Offline
Joined: 2nd Apr 2017
Location:
Posted: 6th Jun 2024 07:43 Edited at: 6th Jun 2024 07:44
How about trying this roundabout method?

1) GetChoosenImage() an image in mobile
2) Got a choosenimage.jpg imgID without transparency
3) Use CreateMemblockFromImage()
4) Perform memblock black magic to convert all the black bytes into transparency
5) Recreate the image with CreateImageFromMemblock()
6) SaveImage() that image as .png
7) ?Win?

Login to post a reply

Server time is: 2024-06-21 21:23:13
Your offset time is: 2024-06-21 21:23:13