|
Forum Index : Microcontroller and PC projects : Reading binary data from a file
| Author | Message | ||||
| William Leue Guru Joined: 03/07/2020 Location: United StatesPosts: 410 |
I am trying to read binary data from a file. Although using: open "foo.bmp" for input as #2 hdr$ = input$(#2, hdr$) Does work, I would really like to read data into an integer array. I tried this: dim hdr(1000) load data "foo.bmp", peek(VARADDR, hdr()) but this gives me a syntax error on the 'load data' line. Any clues? -Bill |
||||
| Martin H. Guru Joined: 04/06/2022 Location: GermanyPosts: 1447 |
I think your parameters are incorrect; here, for example, is how to read the width and height of a PNG file open FN$ + ".png" for input as #1 s$ = INPUT$(24, #1) ' Read width w=ASC(MID$(s$,17,1))*16777216 inc w,(ASC(MID$(s$,18,1))*65536) inc w,(ASC(MID$(s$,19,1))*256) inc w,ASC(MID$(s$,20,1)) ' Read height h=ASC(MID$(s$,21,1))*16777216 inc h,(ASC(MID$(s$,22,1))*65536) inc h,(ASC(MID$(s$,23,1))*256) inc h,ASC(MID$(s$,24,1)) close #1 so it is INPUT$(number of bytes, #Chanalno.) 'no comment |
||||
| William Leue Guru Joined: 03/07/2020 Location: United StatesPosts: 410 |
Thanks a lot, I had it backwards! -Bill |
||||
| Volhout Guru Joined: 05/03/2018 Location: NetherlandsPosts: 5859 |
In the newer pico basics, ASC(MID$ can be replaced by the faster BYTE command. Volhout PicomiteVGA PETSCII ROBOTS |
||||
| William Leue Guru Joined: 03/07/2020 Location: United StatesPosts: 410 |
Has that change been added to Color Maximite version of MMBasic too, Volhout? -Bill |
||||
| The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2026 |