Posted: 6th Jun 2024 0: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.
Posted: 6th Jun 2024 4:08
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.
Posted: 6th Jun 2024 4:34
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.

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:
+ Code Snippet
This$ = GetDocumentsPath()
Write$ = GetWritePath()
Local$ = GetReadPath()
do
    Print(This$)
    Print(Local$)
    Print(Write$)
    Sync()
loop

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? 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?
Posted: 6th Jun 2024 7:43
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?