Qbasicnews.com

Full Version: how can i fetch the WIDTH and HEIGHT of a BSAVE'd sprite
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
i made a simple paint program, but i can figure out how to fetch the WIDTH and HEIGHT of the image after (or before) i load it up.

currently, when i load the image to continue to edit it, i have to manually resize the canvas... i know there is a way to grab the width and height dimensions so that i can have the resize automatic after i BLOAD it.
I'm not quite sure on how are you saving your data, but if you are directly BSAVINg a GET array, you just look in the two first indexes of the array. They contain the sprite dimmension.
First 2 bytes = Width
Second 1 byte (2 bytes) = Height
Let's say your file is "MYPICT.GET".

DIM W AS INTEGER, H AS INTEGER
OPEN "MYPICT.GET" FOR BINARY AS #1
GET#1,8,W
GET#1,,H
CLOSE #1


Now, after you've done that, W is not necessarily your width (just as the first two bytes in the original array weren't necessarily your width). If you generated the picture in a 16-color/4-bit plane video mode (or a 2-color (monochrome)/1-plane mode), for example, then W is in fact your width. Otherwise, you have to divide W by the number of bits per bit plane per pixel (call it "BPPP") to get the actual width of the saved picture. For mode 13, BPPP = 8. For modes 7, 9, 11, and 12, it's 1 (one). If you just want to calculate how many bytes you need in the array that you're going to BLOAD the picture into, you don't actually need to perform that division, however. The number of bytes you need is

BYTES = 4& + PLANES * H * INT((W + 7) / 8),

where PLANES is the number of bit planes for the video mode. (4 for modes 9 and 12, 1 for 11 and 13, for example.)

(If you look up PUT or GET in QB's on-line help. if I remember the right keywords as to where the data is, you can see what BPPP and PLANES are for the various video modes that QB supports. Or you can look in a table in http://www.geocities.com/gstumpff/qbgraph.txt .)
alright, its official, glenns my new best friend Smile

thanx guys
AAAAGH!! You'll be regretting that decision! [Image: biglaugh.gif]
heh,

btw, worked like a champ Smile
:lol: lol
I guess I should point out that if you just want to get the number of bytes that the array needs to allocate, that number is stored directly (well, almost) in the file. You just have to do a little dance to get around a "numerical quirck." The number of bytes originally BSAVED (i.e., the minimum number of bytes your array needs to allocate) is stored in the two bytes starting at byte 6 of the "BLOAD file."

DIM SIZEINT AS INTEGER, SIZELONG AS LONG
'
' After you've opened the file FOR BINARY do:
'
GET#1,6,SIZEINT
'
' SIZEINT would be the number of bytes you need except for the fact
' that it might be negative (because unsigned integers > 32,767 need
' to be wrapped to negative values in order to be stored in a two-byte
' space). So, to get the unsigned (i.e., useful) value for the number of
' bytes to allocate, do:
'
SIZELONG=SIZEINT AND &HFFFF&
'
' or
'
SIZELONG=(CLNG(SIZEINT)+65536&) MOD 65536&



Quote:heh,

btw, worked like a champ Smile