How do you know the bytes to dim using a PUT command?

Quote:

> I want to know how to tell how many numbers to dim and GET before

> using a PUT command. I know it has to do with how big the picture

> is, but I usually mess up.

The number of array elements you need is:

The number of bytes needed to store one plane of one row of your picture

(rounded up to the nearest byte) multiplied by the number of planes,

multiplied by the number of rows, plus four bytes to store the x and y

dimensions (as two 2-byte integers), divided by the number of bytes per

element in whatever numeric type you're using.

So, how many bytes do you need to store a row? Well, that depends on

what screen mode you're using, and how many bits-per-pixel it uses, and

how many bit planes it has.

The following table and formula are from the QBASIC Help system (follow

the "Screen Image Arrays and Compatability" link in the "GET (Graphics)"

Help screen):

Horizontal

Bits-per-pixel- resolution

Screen mode per-plane Planes (in pixels)

1 2 1 320

2, 4, 11 1 1 640

3 1 1 720

7 1 4 320

8, 9(> 64K video memory), 12 1 4 640

9(64K video memory), 10 1 2 640

13 8 1 320

The following formula gives the required size, in bytes, of an array used

to hold a captured image:

size% = 4 + INT(((PMAP (x2!, 0) - PMAP (x1!, 0) + 1) *

(bits-per-pixel-per-plane%) + 7) / 8) * planes% *

(PMAP (y2!, 1) - PMAP (y1!, 1) + 1)

=-=-=-=-=-=-=-=-=-=-=-=

That formula may seem a bit daunting at first, so let's break it down into

individual steps:

'First, convert from World Coordinates to physical screen coordinates.

'This step is not necessary if you're not using the World Coordinates as

'set by a WINDOW statement:

RealX1% = PMAP(x1!, 0)

RealX2% = PMAP(x2!, 0)

RealY1% = PMAP(y1!, 1)

RealY2% = PMAP(y2!, 1)

'Next, determine the X and Y size of your graphic:

Xsize% = RealX2% - RealX1%

YSize% = RealY2% - RealY1%

'Now, determine how many 8-bit bytes are needed for each line of pixels in

each plane, and round up to the nearest whole byte:

PixelBytes% = ((XSize% * bits-per-pixel-per-plane%) + 7) \ 8

'Multiply that by the number of planes:

BytesPerLine% = PixelBytes% * planes%

'Then multiply by the total number of lines:

BytesNeeded% = BytesPerLine% * YSize%

'Add 4 bytes to store the X and Y dimensions:

TotalBytes% = BytesNeeded% + 4

'And finally, divide by the number of bytes per array element (2 for

INTEGER arrays, 4 for LONG or SINGLE, and 8 for DOUBLE), rounding up:

ElementsNeeded% = (TotalBytes% + BytesPerElement% - 1) \ BytesPerElement%

Now you know how many array elements you need. DIMension an

appropriately-sized array, and you're ready to go.

Hope that helps.

---

Glen Blankenship