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 / Minor image loading issue on Android

Author
Message
Naphier
13
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 24th Jun 2013 21:58 Edited at: 24th Jun 2013 22:47
If you open alter the extension of an image file then the AppGameKit Player 10814 will fail to load the image on Android 4.2 and 2.3

For instance take any PNG file and change its extension to X
Attempt to load that image onto a sprite in the AppGameKit player.
It will fail, giving the blank sprite "X" image.

Not sure if this is new or not. Kind of a pain because now I'll have to rewrite a bit of my encryption coding so I also store the file's original extension. Works fine in Windows. Would be nice if it worked across platforms.

You guys think this is a bug or not?



Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 24th Jun 2013 22:44
each file without text have a 4 char code for the contens.
maybe you can use better a xor encryption as .bin file,
fill a memblock, xor again and use CreateImageFromMemblock.

in your example you wrote a .jpg and you will load a .x file.
Naphier
13
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 24th Jun 2013 22:46 Edited at: 24th Jun 2013 22:51
The problem's not with the encryption. The file above was not encrypted at all I was just mentioning that because my decryption process simply names all files with the same extension. I'll need to modify it to use the original extension. Just more work, but not very hard.

Sorry about the typo in the code. I've fixed it (you might also not that I had the first file copying section commented out). It yields the same results. Even if you take a file without writing it. Just take any of your image files and change the extension in the read only media directory. They fail to load on Android unless their extension is correct.

Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 24th Jun 2013 23:07
I suspect that the LoadImage takes clues from the extension. I think that .jpg, .png and .gif have different file formats.

If that is the case, then the LoadImage command doesn't know which file format to use with .ANY.

I could be wrong.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 24th Jun 2013 23:16 Edited at: 25th Jun 2013 09:21
i think also what Ancient Lady said, its the simplest way else
"AGK" must read the beginning file and select then the loading routine.

edit:
maybe it is both, extension+header
Cliff Mellangard 3DEGS
Developer
18
Years of Service
User Offline
Joined: 20th Feb 2006
Location: Sweden
Posted: 24th Jun 2013 23:24
Why dont you simply rename the file Before loading with an png extension and then delete it when loaded or rename it back to your encryption?
This is anyway done in the background and the user dont usually see it.

Android 2.3 , ZTE Skate , 480x800 , 800 mhz , Samsung Galaxy Y , 240x320 , 832 mhz , Sony ericson arc 480x854 , 1 ghz
Android 4.0 , Dmtech 3g 9738B , 1024x768 , 9.7 inches , 1.2 ghz
Naphier
13
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 25th Jun 2013 03:40
@AL - That would make sense, but in Windows AppGameKit doesn't care what the extension is... I've used all sorts of arbitrary extensions with no problem. That's where the problem lies. Windows LoadImage seems to read the header of the file to determine the image type. Android seems to rely on the extension. So it is doing different things depending on platform.

@Cliff - That's what I'll be doing and is what is going on anyway. Just without the renaming part.

I can't really understand why AppGameKit would use different LoadImage routines for Android vs. Windows and why it would rely on a file's extension to determine the type... that's what headers are for!

Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 25th Jun 2013 05:13
Well, the Windows and Android (and all other platforms) have different libraries built for the platform. Plus, the Android platform has Java bits mixed in (although I don't think they play a major role in image loading, but they might).

So, it is not impossible that the core platform stuff available gets into the mix about file names.

But, assuming that it is totally controlled within the libraries, one might also assume that the files are read as you suggest. Read the first few bytes to get the file type and go from there.

So, we need someone from TGC to weigh in on the question.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Naphier
13
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 25th Jun 2013 16:20
Quote: "So, we need someone from TGC to weigh in on the question."


Agreed!
I can understand both ways too, but it seems no matter what that the header must be read, otherwise how would AppGameKit know the width and height of the image?

So interestingly, I just opened a PNG file with the extension DEC with the native photo gallery app on my HTC Dinc2 and it opened with no problem. So in my opinion AppGameKit is doing something wrong.

Paul Johnston
TGC Developer
21
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 29th Jun 2013 02:58
Although Android Java does provide an image loading library, Android NDK does not, so we compile some third party libraries for PNG and JPG loading. We read the extension and then either pass it to the PNG library or the JPG library. It's possible we could instead read the headers before passing it off to a library for loading, but without knowing the intricacies of the headers the extension was a safer bet.

iOS, Windows, and Mac all use platform APIs to load the image for us.
Hodgey
14
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 29th Jun 2013 06:43 Edited at: 29th Jun 2013 06:49
@Naphier: it's possible that it might be your code (I could be wrong). Try changing from a post-check loop to a pre-check loop. This code works fine for me on Windows:


It's possible that the repeat-until is adding an extra char or something which throws the file out of whack. I also only skimmed over the thread so I'm not sure if it has already been resolved.

Edit-scratch most of what I said above the repeat-until works fine on this end as well using Beta12.

Edit 2- missed the Android perspective completely! Ignore everything I just said!

Naphier
13
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 29th Jun 2013 15:37
@Hodgey - thanks for trying :-P

@Paul - that answer makes a lot more sense. Thank you for sharing your knowledge. I understand if you guys don't change it (though I think it should, to provide consistency across platforms). Knowing that it won't be changed anytime soon would it be proper for me to make a note on the help files?

Login to post a reply

Server time is: 2024-05-03 15:18:53
Your offset time is: 2024-05-03 15:18:53