Re: writing numbers to file
David,
your trouble is caused by the abominable get() function. For
explanation you must go to its section in the library.doc. The last
paragraph of the description block starts:
Multiple "top-level" objects in the input stream must be
separated from each other with one or more "whitespace"
characters (blank, tab, \r or \n).
The five sequences in your bitmap.dat are unfortunately bunched
together without any separators. The easiest fix would be to insert a
space or a linefeed after each sequence, using something like puts(fn,
" ") or puts(fn, "\n") statements.
Happily I have never used QB in anger, but I hope it can use bitmap
files (.bmp). If it does, you would be much better off storing your
images using the save_bitmap() function from image.e. Apart from
limited portability of *.bmp files within the Microsoft universe, it's
also a simpler as well as more space efficient solution.
jiri
----- Original Message -----
From: <dstanger at belco.bc.ca>
To: "EUforum" <EUforum at topica.com>
Sent: Tuesday, 3 July 2001 13:57
Subject: writing numbers to file
> Hello again,
>
> Thanks, Irv, for your help. Using your suggestions I have gotten a
little
> further but I am still having problems. Here is my troubled code:
>
> include image.e
> include graphics.e
>
> integer fn, n
>
> sequence bitmap, data
> bitmap = {}
> data = {}
>
> n = graphics_mode(257)
>
> --The bitmap is a 5 x 5 white square
> bitmap = read_bitmap("c:\\windows\\desktop\\test.bmp")
> all_palette(bitmap[1] / 4)
> display_image({0,0}, bitmap[2])
>
> --This file holds the color numbers of the bitmap...
> fn = open("bitmap.dat", "w")
>
> --Scans the colors from {0,0} to {5,5} and writes them to
bitmap.dat...
> for y 0 to 4 do
> data = get_pixel({0,y,5})
> print(fn, data)
> end for
>
> close(fn)
>
> --Here is where I attempt to redraw the bitmap using the data in
bitmap.dat:
> clear_screen()
>
> fn = open("bitmap.dat", "r")
>
> for v = 0 to 4 do
> data = get(fn)
> if data[1] = GET_SUCCESS then
> data = data[2]
> else
> abort(0)
> end if
> pixel(data,{0,v})
> end for
>
> close(fn)
>
> If you run it you will see my problems. The data is saved as a
sequence for
> each line of the bitmap and I can't seem to read it back properly.
Any
> suggestions? My real hope is that I will be able to use this program
to
> convert bitmaps into something that QB can read and display. I
thought that
> it would be simple but is turning into a real headache (isn't that
always
> the way with programming?;) ).
>
> Thank you all,
> David S.
|
Not Categorized, Please Help
|
|