IncludeBinary and ExpandBinary

Share your advanced PureBasic knowledge/code with the community.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

IncludeBinary and ExpandBinary

Post by BackupUser »

Code updated for 5.20+

Restored from previous forum. Originally posted by Rings.

Often in this forum there is the question about including graphics,sound etc. into the File itselfs.Here is a way to do it.

Code: Select all

;ExpandBinary (c) 2002 by Siegfried Rings (known as the 'CodeGuru')
;expand files which includes via IncludeBinary

Procedure ExpandBinaryfile(fileName.s)
  If CreateFile(1, fileName)          ;create file
    L1 = ?IB2 - ?IB1                  ;get size of included binary
    WriteData(1, ?IB1, L1)            ;write included binary to file
    CloseFile(1)                      ;close file
  EndIf
  ProcedureReturn 1
  IB1:
  IncludeBinary "c:\original.bmp"     ;the file to include
  IB2:
EndProcedure

ExpandBinaryfile("c:\expanded.bmp")   ;the file to create
As i know, Pro's of you can also use the Pack/Unpack functions , but that is another topic yet :wink:


Its a long way to the top if you wanna .....CodeGuru

Edited by - Rings on 10 April 2002 22:29:39
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Franco.

I like the trick to get the size of an unknown file...

BTW Why do you have the subs inside your procedure?



Have a nice day...
Franco

Sometimes you have to go a lonely way to accomplish genius things.

Edited by - franco on 10 April 2002 23:55:44
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by tinman.
BTW Why do you have the subs inside your procedure?
The first one would be to access the included binary, and the second would be to calculate it's size

--
It's not minimalist - I'm increasing efficiency by reducing input effort.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Franco.
The first one would be to access the included binary, and the second would be to calculate it's size

That's why I said:
I like the trick to get the size of an unknown file...

But I asked:
BTW Why do you have the subs INSIDE your procedure?


Have a nice day...
Franco

Sometimes you have to go a lonely way to accomplish genius things.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Rings.
I like the trick to get the size of an unknown file...
BTW Why do you have the subs inside your procedure?
Franco
thx Franco.
Well Why i have the Binary inside the procedure ?.Why not.
Its easier to take a look over it.You can also add them at the
end of your code and make the Procedure more comfortable(take the 2 ?Label as parameters).
Take this only as a hint how we can do it.As i also said, i prefer the solution
with Packed files to decrease filesize.But that's another topic.

Its a long way to the top if you wanna .....CodeGuru
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by freak.

Well, nice trick, but is it possible to include a BMP or ICO file, anduse it without having to expand it to a file first

Timo

A debugged program is one for which you have not yet found the conditions that make it fail.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Rings.
Well, nice trick, but is it possible to include a BMP or ICO file, anduse it without having to expand it to a file first

Timo
Everything is possible, but it is hard coz you have to expand raw Bitmap-Data and transfer it to the GraphicsBitmapBuffer in Memory.ElChoni has posted an example how to modify Bitmap in Memory.Its yours to copy the Data from Binary to GraphicsBuffer.You should also indeep in BitMap-structures and SetBit Api.
I would prefer saving first to disk, coz its easier.And it cost not so much time while executing.And you don't have to know all the Bitmapstuff.


Its a long way to the top if you wanna .....CodeGuru
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by freak.

I now read the Post from El_Choni and, you're right, it's hard.
Looks like i'm going to svae to disk first.

A debugged program is one for which you have not yet found the conditions that make it fail.
BackupUser
PureBasic Guru
PureBasic Guru
Posts: 16777133
Joined: Tue Apr 22, 2003 7:42 pm

Post by BackupUser »

Restored from previous forum. Originally posted by Rings.

:=)

Edited by - Rings on 11 April 2002 19:09:37
Post Reply