1. Writing numbers to files

Hello,

I hope that someone can help me with this DOS program:

I am obtaining the color numbers of a bitmap on the screen using get_pixel()
and then writing them to a file. When I use puts() to write them to the file
it saves the color numbers as characters which I don't want. If I use print
to write them it does so as numbers but puts them in a lump that is useless
to me. Eventually, I want to be able to read the numbers out of the file and
convert them back to colors on screen using pixel() but until I can save
them in a way that I can read them again I am stuck.

So, what I am looking for is either a way to turn the characters back into
numbers or a way to seperate the lump of number produced by print. Or a
better way to save them to file in the first place!

Many thank,
David S.

new topic     » topic index » view message » categorize

2. Re: Writing numbers to files

From: <dstanger at belco.bc.ca>

> I hope that someone can help me with this DOS program:
> I am obtaining the color numbers of a bitmap on the screen using
> get_pixel() and then writing them to a file. When I use puts() to
> write them to the file
> it saves the color numbers as characters which I don't want. If I use
print
> to write them it does so as numbers but puts them in a lump that is
useless
> to me. Eventually, I want to be able to read the numbers out of the file
and
> convert them back to colors on screen using pixel() but until I can save
> them in a way that I can read them again I am stuck.

First of all, are you using get_pixel ({x,y}) -- one point at a time, or
get_pixel({x,y,n})
-- getting a series of 'n' points?
The first one returns a small integer, the second an 'array' of integers.

Since these are integers, seeing or saving them as characters won't be good.
Integers often go higher than 256.

What's wrong with just using print(fn,s) ?
That will print the numbers out in this form:

{254,464,5457,675,2353,5435,346,1,4}....and so on.

Reading them back in is just s = get(fn)
 if s[1] = GET_SUCCESS then s = s[2]
else -- error routine goes here

Print() and it's partner get() can write and read ANY Euphoria sequence, no
matter how complex.

If you need the numbers formatted to be more human readable, use a loop with
printf()
If you do that, you can load them into a text editor. The problem will come
when
you want to load them back into a Euphoria program, you'll have to do some
parsing. More work.

Regards,
Irv

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu