| Run length encoding for saving black and white imagesAugust 11 2009 at 6:02 PM | Anon (no login) | |
| Can use PRINT and INPUT instead of PUT and GET if you prefer. Also, you can modify it to decode to an array instead of to the screen if you want to, though it would probably be more efficient to just decode to the screen and GET it to an array.
DEFINT A-Z
SUB SAVEIMG(X1, Y1, X2, Y2, file$)
OPEN file$ FOR BINARY AS #1
c=0:count=0
FOR y = Y1 to Y2
FOR x = X1 to X2
IF POINT(x,y) <> c THEN PUT #1, , count: c = c XOR 1 ELSE count = count + 1
NEXT
NEXT
CLOSE #1
END SUB
SUB LOADIMG(X1, Y1, X2, Y2, file$)
OPEN file$ FOR BINARY AS #1
c=0:count=0
FOR y = Y1 to Y2
FOR x = X1 to X2
IF count=0 THEN GET #1, ,count: c = c XOR 1 ELSE PSET(x,y): count=count-1
NEXT
NEXT
END IF
|
|
Newbies usually go to www.qbasic.com and click on
The QBasic Forum
Forum regulars have their own ways, which include
The QBasic Community Forums
|