PngLib - Extract data from png files (width, height, color depth etc)

Guys,

Remember that system.DocumentsDirectory doesn’t exist on android:

http://www.coronalabs.com/blog/2012/09/26/faq-wednesday-ios-builds-api-docs-and-android/

file://localhost/Users/dcgm1986/Programming/Projects/iOS/Corona/Other/Api-Web-Daily/html/api/library/system/pathForFile.html

(see gotchas)

So if thats where your attempting to get a png file via png lib, thats your issue (on Android)
[import]uid: 84637 topic_id: 26389 reply_id: 132393[/import]

Danny,

Thanks for writing so quickly. To be clear, I ran into a case where pnglib failed to find the width/height of a png that was in the ResourcesDirectory.

However…

I was in a hurry so I skipped using pngLib at the time and input the values manually. The mistake could well have been mine, but beyond basic debugging, time constraints force me to skip using it for then.

I’ll have to try again and debug more later. I do want to use this resource more.

So, thanks for the support and for this this resource.

Cheers,
Ed [import]uid: 110228 topic_id: 26389 reply_id: 132419[/import]

@Danny,
Dang so the short answer is that this library will work with IOS only right? I read the first link you posted and thats what I gathered, that really sucks. (second link is broken). Guess its back to putting in all my png’s width and height by hand! [import]uid: 19620 topic_id: 26389 reply_id: 132433[/import]

@rxmarcall:

I wouldn’t go that far. It depends on your usage I guess. For instance, on my own project I don’t load any images from the documents directory so it’s fine.

I will see what I can do about the android side of it when I have some time. [import]uid: 84637 topic_id: 26389 reply_id: 132436[/import]

I don’t think I do either? I guess I am confused on how that works. I just have my images in a sub folder called “images” on the root of my project. When I build my project do those images get put in the “documents directory”? I am not trying to do anything special, these are just basic images I use in my project. [import]uid: 19620 topic_id: 26389 reply_id: 132438[/import]

In that case this should work for you fine.

Isn’t it working for you? :slight_smile: [import]uid: 84637 topic_id: 26389 reply_id: 132439[/import]

Maybe I need to have all my images on the root of my project for it to work? I have mine all organized e.g. (images/story1/page1/item1.png). [import]uid: 19620 topic_id: 26389 reply_id: 132442[/import]

@rxmarccall,

No, images, sound files, etc. that you include in your original build are all found in the (default) path area:
system.ResourceDirectory

However, some apps need to create files or download and store files. Because you can’t write to the system.ResourceDirectory on a device (it is read-only), you need somewhere else to put files.

* system.DocumentsDirectory - A location for persistent (saved between app runs) data.
* system.TemporaryDirectory - A place for non-persistent (may be deleted when the app closes) data.

So, the question for you that still exists is, “Why can’t you read the data from the PNG file that is under system.ResourceDirectory?”

PS - I’m going to stop responding to this thread till I get a chance to debug my (similar) problem and give some feedback on error messages, etc.

Again, thanks for the support and the lib Danny. [import]uid: 110228 topic_id: 26389 reply_id: 132446[/import]

@emaurina,
So are you getting the same error that I am getting? Or are you running into a different problem? [import]uid: 19620 topic_id: 26389 reply_id: 132483[/import]

Can’t figure out why this library is giving me troubles. I am sending my app out for beta testing this week so I guess I’ll need to revert to my old crappy methods. Shouldn’t be an issue that my pnglib.lua is in a “scripts” folder and not on root right? [import]uid: 19620 topic_id: 26389 reply_id: 132637[/import]

@Danny,
Sorry to be a bother, I just wanted to post a snippet showing how I am using PngLib, to see if you guys can see if I am doing anything wrong…

[lua]local storyImagePath = “images/story” …global.thisStoryNumber… “/page”…global.thisPageNumber…"/item" …i… “.png”
storyCharacters[i] = display.newImageRect(storyImagePath, (pngLib.getPngInfo(storyImagePath).width * 0.5), (pngLib.getPngInfo(storyImagePath).height * 0.5) )

storyCharacters[i].x = characterInfo[i].xSnap
storyCharacters[i].y = characterInfo[i].ySnap
objectGroup:insert(storyCharacters[i])[/lua] [import]uid: 19620 topic_id: 26389 reply_id: 132669[/import]

Can’t figure out why this library is giving me troubles. I am sending my app out for beta testing this week so I guess I’ll need to revert to my old crappy methods. Shouldn’t be an issue that my pnglib.lua is in a “scripts” folder and not on root right? [import]uid: 19620 topic_id: 26389 reply_id: 132637[/import]

@Danny,
Sorry to be a bother, I just wanted to post a snippet showing how I am using PngLib, to see if you guys can see if I am doing anything wrong…

[lua]local storyImagePath = “images/story” …global.thisStoryNumber… “/page”…global.thisPageNumber…"/item" …i… “.png”
storyCharacters[i] = display.newImageRect(storyImagePath, (pngLib.getPngInfo(storyImagePath).width * 0.5), (pngLib.getPngInfo(storyImagePath).height * 0.5) )

storyCharacters[i].x = characterInfo[i].xSnap
storyCharacters[i].y = characterInfo[i].ySnap
objectGroup:insert(storyCharacters[i])[/lua] [import]uid: 19620 topic_id: 26389 reply_id: 132669[/import]

So Sad… No update to the Lib so it will work on android!!!

Cheers,

Gullie

So Sad… No update to the Lib so it will work on android!!!

Cheers,

Gullie

An Android APK is really a zip file. The files in the resource directory are inside the APK file, therefore they are compressed within a zip file (instead of residing in an actual directory). The Lua I/O API such as io.open() is unable to open/extract files inside a zip file, thus it cannot open files within an APK.

Short answer: it won’t work on android.

An Android APK is really a zip file. The files in the resource directory are inside the APK file, therefore they are compressed within a zip file (instead of residing in an actual directory). The Lua I/O API such as io.open() is unable to open/extract files inside a zip file, thus it cannot open files within an APK.

Short answer: it won’t work on android.

Please modify the original posting to clearly state that the library does not work on Android, at least not with images from the package. Corona is supposed to be a cross-platform framework and users of the library implicitly expect that it will work on all platforms. Discovering such discrepancies only once the entire artwork is ready will cause much additional work to uproot your library and even missed deadlines.

Please modify the original posting to clearly state that the library does not work on Android, at least not with images from the package. Corona is supposed to be a cross-platform framework and users of the library implicitly expect that it will work on all platforms. Discovering such discrepancies only once the entire artwork is ready will cause much additional work to uproot your library and even missed deadlines.