Saving a PNG?

Blitz3D Forums/Blitz3D Programming/Saving a PNG?

John Pickford(Posted 2006) [#1]
My game need to save an image which will be uploaded and displayed on a web page. Ideally this will be PNG (the PHP library can covert this).

After a quick investigation it looks like this isn't a trivial task. Has anyone got any code to do this? I notice BMAX can save to PNG. Can I create a DLL in BMAX?


Dreamora(Posted 2006) [#2]
No you can't, its not allowed.


John Pickford(Posted 2006) [#3]
What do you mean, not allowed?


Dreamora(Posted 2006) [#4]
Making DLL with BMax


Matty(Posted 2006) [#5]
I think it is mentioned in this thread:

http://www.blitzbasic.com/Community/posts.php?topic=53607&hl=dll%20making


LineOf7s(Posted 2006) [#6]
...or, perhaps a little more helpfully, you could use this:

http://www.blitzcoder.com/cgi-bin/showcase/showcase_showentry.pl?id=snarty09252003024804&comments=no


Beaker(Posted 2006) [#7]
Out of interest: what will the PHP library convert it to?


big10p(Posted 2006) [#8]
Yeah, I use FreeImage with Paul Snart's Blitz3D wrapper. I cut down the wrapper to my own requirements and fixed a few minor bugs. It only saves images in 24-bit, though. Here's the code, in case it's of any use:



P.S. It seems a bit strange that Blitz3D can't save PNG images natively, given that it uses FreeImage itself. :/


John Pickford(Posted 2006) [#9]
Cheers Big10p. I'll have a go with that code.

Beaker, I think it gets converted to jpg.


John Pickford(Posted 2006) [#10]
Big10p, Do I need a decls file to use that? I've found the dll.

Also, what's the deal with the licence? Can I use this commercially?


big10p(Posted 2006) [#11]
Sorry, forgot about the decls - you actually need 2:

freeimage.decls


kernel32.decls


Also, what's the deal with the licence? Can I use this commercially?
Well, you can certainly use FreeImage commercially. As I said, Blitz3D actually uses it as an image loader. From the FreeImage site:

When using FreeImage in your open source or commercial application, you are REQUIRED to :
distribute the license (GNU GPL or FIPL) you choosed with your application (i.e. the TXT file)


provide a suitable acknowledgement, either in the program's "About" box or in the user's manual (or both), for example :

This software uses the FreeImage open source image library. See http://freeimage.sourceforge.net for details.
FreeImage is used under the (GNU GPL or FIPL), version (licence version).



As for the wrapper, I can't actually remember where I sourced it. However, I'm sure it's free for commercial use, which it says in the comments at the top of the code. They're comments by the original author, not me.


big10p(Posted 2006) [#12]
BTW John, I decided to stick with using the version of the FreeImage dll that was shipped with the wrapper, just in case a newer version of the dll caused compatibility issues with it.

Using a newer version of the dll will probably be fine, but if you want the older version for the same reason, email me (addy in profile) and I'll shoot it over to you.


John Pickford(Posted 2006) [#13]
Got it all working now - cheers!


big10p(Posted 2006) [#14]
No problem. :)


LineOf7s(Posted 2006) [#15]
At the risk of sounding bitter and twisted, I posted a link to the Freeimage wrapper and DLL nine posts and eleven hours ago.


big10p(Posted 2006) [#16]
Hmm, when I looked at that link earlier, I thought it was the B+ only version. My version is a bit different to that one, anyway - cut-down, bug-fixes. Ah, well. :)


LineOf7s(Posted 2006) [#17]
And a stellar job you've done with it too. :o)

Since you're around, I'll ask: which bit does yours replace? Just the freeimage.bb (aka freeimage3D.bb) include file? All the rest works the same?


big10p(Posted 2006) [#18]
I didn't really do much. Just combined everything into a single include file, chopped everything out I didn't need and fixed a couple minor bugs. It's still 100% Paul Snarts work, as far as I'm concerned. :)


Shifty Geezer(Posted 2008) [#19]
I find myself needing to save .pngs and have grabbed the latest FreeImage lib and this wrapper by big10p. It works save for the .png being saved upside down! Any fixe?


VIP3R(Posted 2008) [#20]
What version of the FreeImage DLL are you using?

Are the other image types saving correctly?


Shifty Geezer(Posted 2008) [#21]
Long time no see (again ;) )
Freeimage is version 3.10.0. .bmp's are upside down as well as .pngs.


markcw(Posted 2008) [#22]
Please don't dredge up old posts.

http://www.blitzbasic.com/codearcs/codearcs.php?code=1732