Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2018-09

Bitmap-as-const-and-write-to-file-thingy

5 messages · 3 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Marc Santhoff

Hi,

a program im fiddling with uses exactly 2 small .gif pictures that are to be stored in the code and written out to the file system.

For several reasons - no gif writer, complicates ressouce file handling, linking fpimage or similar - I want to handle those files directly in code, having an array of hex bytes and some code writing those consts to file.

What I need:

- A program taking a binary file and spitting out pascal code for the const array. I know I have seen such program in the past, but do not know where.

- Some hints on using this constant for making files out of them. Currently I'm plannig to use a TFileStreaam writing out Bytes, should do.

Any pointers or hints, please?

TIA,
Marc

Marc Santhoff

Reply by email

Tomas Hajny
to Marc Santhoff

On Wed, September 19, 2018 23:58, Marc Santhoff wrote:

Hi,

.
.

Show quoted text 5 lines
What I need: - A program taking a binary file and spitting out pascal code for the const array. I know I have seen such program in the past, but do not know where.

data2inc is included with FPC.

- Some hints on using this constant for making files out of them. Currently I'm plannig to use a TFileStreaam writing out Bytes, should do.

Indeed, should do; simple file of byte and BlockWrite should do as well.

Tomas

Reply by email

Bo Berglund
to Marc Santhoff: a program im fiddling with uses exactly 2 small .gif pictures that are to be stored in…
Marc Santhoff wrote
Any pointers or hints, please?

You can convert any file you like to an inc file with pascal syntax:

data2inc -A -B laz/images/ide_icon48x48.png datatest.inc icon48x48

This will produce a datatest.inc file ready to be included in your project and with content looking like this:

const icon48x48 : array[0..4236] of byte=(
$89,$50,$4E,$47,$0D,$0A,$1A,$0A,$00,$00,$00,$0D,$49,$48,$44, ....
$45,$4E,$44,$AE,$42,$60,$82);

data2inc is installed with fpc/lazarus ready for use. I used a png file shipped with lazarus as the example above.

Bo Berglund Developer in Sweden

Reply by email

Marc Santhoff
to Tomas Hajny: . . data2inc is included with FPC. Indeed, should do; simple file of byte and BlockWrite…
Tomas Hajny wrote 14 lines
On Wed, September 19, 2018 23:58, Marc Santhoff wrote: Hi, . . > What I need: > > - A program taking a binary file and spitting out pascal code for the > const array. I know I have seen such program in the past, but do not know > where. data2inc is included with FPC.

FPC is amazing! Batteries included. :)

> - Some hints on using this constant for making files out of them. > Currently I'm plannig to use a TFileStreaam writing out Bytes, should do. Indeed, should do; simple file of byte and BlockWrite should do as well.

I'll try soon,

Thank you very much.

Marc Santhoff

Reply by email

Marc Santhoff
to Bo Berglund: On Wed, 19 Sep 2018 23:58:36 +0200, Marc Santhoff You can convert any file you like to an…

Oncemore using the correct from address...
Sorry moderation.

Bo Berglund wrote 19 lines
On Wed, 19 Sep 2018 23:58:36 +0200, Marc Santhoff wrote: > Any pointers or hints, please? You can convert any file you like to an inc file with pascal syntax: data2inc -A -B laz/images/ide_icon48x48.png datatest.inc icon48x48 This will produce a datatest.inc file ready to be included in your project and with content looking like this: const icon48x48 : array[0..4236] of byte=( $89,$50,$4E,$47,$0D,$0A,$1A,$0A,$00,$00,$00,$0D,$49,$48,$44, .... $45,$4E,$44,$AE,$42,$60,$82); data2inc is installed with fpc/lazarus ready for use. I used a png file shipped with lazarus as the example above.

Done. Cool stuff. :)

Thanks.

Marc Santhoff

Reply by email