Qbasicnews.com

Full Version: Graphics not drawing correctly
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
How do you figure the size of an array needed to hold a graphic?
My Graphics get and put correctly but if i try bsave and bload only half the grphic is displayed when I put it on the screen. Here is example code

TO SAVE GRAPHIC:

dim sh(129)
screen 13
line(5,5)-(21,21),4,bf
get(5,5)-(21,21),sh
def seg = varseg(sh(0))
bsave "whatever.gfx",0,129
def seg

TO LOAD GRAPHIC:

dim sh(129)
screen 13
def seg=varseg(sh(0))
bload "whatever.gfx",0
def seg
put(10,10),sh,pset



Only half my graphic shows up and if i increase the size of the array then I get a illegal function call

ARRRRGH

Any suggestions please email me bmunnjr@hotmail.com
To calculate the size needed to hold your graphic, assuming you're using an array of INTEGER:
((width * height) \ 2) + 2

e.g. to store a 50x50 pixel image, you'd need to do: DIM myImage(1252) AS INTEGER

The reason for this is that an INTEGER occupies 2 bytes -- that's why you need to divide the area by 2. Also, you have to make room for the GET/PUT header, which is 4 bytes (or 2 INTEGERs).

The problem with your code is in the BSAVE line. You've done the DEF SEG correctly, but following this, you should have:

BSAVE "whatever.gfx", VARPTR(sh(0)), 129 * 2

The first argument is the file name to save it is (as you know), the second argument is the offset to the image in memory and the last argument is the length of the image in -bytes-.

So if you're saving our supercool 50x50 image, you'd do:

BSAVE "amazing.gfx", VARPTR(myImage(0)), (50 * 50) + 4

EDIT:
I forgot to say anything about loading the image; the first argument to BLOAD is the file name and the second argument is the offset in memory to store it in... so you'd need to change your code to this:

BLOAD "whatever.gfx", VARPTR(sh(0))
Thanks for the info I really appreciate the help. This has been stopping me from getting anywhere on the graphics screen and ya can only do so much with the text screen. I figured i should be using a pointer to the actual array but all the Tut's i have read so far never mentioned it.

QB Rocks!!!!


Strydre