1. 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.

new topic     » topic index » view message » categorize

2. Re: writing numbers to file

From: <dstanger at belco.bc.ca>
> 
> --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

Try this instead:
 for y =  0 to 4 do
      data = append(data, get_pixel( {0,y,5} )
 end for
 
 That should create a nested sequence, which you print to disk using:

 fn = open( "BitMap.DAT", "w")  
  print(fn, data)
 close(fn)
 
and then read back  as follows:

 fn = open( "BitMap.DAT","r")
  data = get(fn)
  if data[1] = GET_SUCCESS then data = data[2]
  else puts(1,"ERROR")
  end if
 close(fn)

Regards,
Irv

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

3. 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.

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

4. Re: writing numbers to file

----- Original Message -----
From: <dstanger at belco.bc.ca>
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:
>
Here's a program that does what you want. To test, I made a blue bitmap with
a diagonal
white line from top left to bottom right.

include get.e
include image.e
include graphics.e
atom x, fn
object bitmap,data
x = graphics_mode(257)
bitmap = read_bitmap("C:\\bitmap1.bmp")
all_palette(bitmap[1] / 4)
display_image({10,10}, bitmap[2])

data = {}
for y = 10 to 14 do
    data = append(data, get_pixel({10,y,5}))
end for

x = graphics_mode(0)

fn = open("BMP.DAT","w")
print(fn,data)
close(fn) -- writes the following file:

{{255,3,3,3,3},{3,255,3,3,3},{3,3,255,3,3},{3,3,3,255,3},{3,3,3,3,255}}
Note how the 255 (white) moves across the columns

Read it back in as described earlier, using get()
Hope that helps,
Irv

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

Search



Quick Links

User menu

Not signed in.

Misc Menu