Incbin

BlitzMax Forums/BlitzMax Beginners Area/Incbin

(tu) ENAY(Posted 2006) [#1]
INcbin looks like a pretty snazzy tool but I don't know how to use it from the docs. Can anyone post a sample please of how to compress 1 image into an .exe and display it on screen? :)


ImaginaryHuman(Posted 2006) [#2]
Somewhere in your code, add the line:

IncBin "WhateverPath/Whereverelse/YourPicture.PNG"

'Then to use it, go:

Local IM:TImage=LoadImage("INCBIN::WhateverPath/Whereverelse/YourPicture.PNG")

Graphics 640,480,0
DrawImage IM,0,0
Flip
WaitKey
End


(tu) ENAY(Posted 2006) [#3]
When I tried earlier i kept getting errors on the "INCBIN::" line

However I'm loading images in through a for loop and having strange text strings, and it doesn't seem to work.

Does the first Incbin append it to exe and can only be called once?

So for example, do I need to incbin all my stuff at the head of my code (like how you do when you read data variable) ?

Ta for the help :)


Mystik(Posted 2006) [#4]
Hi

You will need a seperate incbin "" line for every file you want attached.

You can use variables in the filenames later though. I use them all the time:-

bg:timage=LoadImage("incbin::General\themes\"+gTheme[gThisTheme].name+"-bg.png")


You must ensure that the case is exactly the same as the original incbin "" command though. It will fail otherwise.

Steve.


ImaginaryHuman(Posted 2006) [#5]
What incbin does is it allows data to be stored in the executable, as is, as binary data. It doesn't matter where you put it in your sourcecode, although I'm thinking it should at least be outside of any loops/types/functions/if-endif's etc. I usually put it at the end of my code, but you could put it near the start.

It will include the file you specify, as is, without any modifications. You can also get a pointer to the file with IncBinPtr() (I think), as included, so that at runtime you could access the file from within your excutable - the included version of it. Then all you need to do is, when loading the file like you would normally, instead of giving a path of the file on disk, you put "incbin::" at the start of the path and leave the rest the same.

Yes you have to use the same path and filename for the Incbin statement and the statement that does something with the file, e.g. LoadImage. You can't use variables in the Incbin filename, but you can use variables in creating your file path from your LoadImage or whatever. It is case sensitive, and you can access the included file as many times as you like.