Posts: 143
Threads: 35
Joined: Oct 2004
ive tried every BMP loader i can find but none of them will work either their is an error in the program itself and it wont run or it wont load for unknown reasons!! is there one out there that somone knows will work, cause im tired of my drawing out data staments.
Posts: 3,522
Threads: 189
Joined: Dec 2003
qb45/71:
Code: DEFINT A-Z
TYPE BMPHeaderType
ID AS STRING * 2
Size AS LONG
RSV1 AS INTEGER
RSV2 AS INTEGER
offset AS LONG
HORZ AS LONG
WID AS LONG
HEI AS LONG
PLANES AS INTEGER
BPP AS INTEGER
COMPRESSION AS LONG
IMAGESIZE AS LONG
xRes AS LONG
yRes AS LONG
CLRUSED AS LONG
CLRIMPORT AS LONG
Pal AS STRING * 1024
END TYPE
DECLARE SUB LoadBMP (DestSeg%, SegxRes%, SegyRes%, File$, sX%, sY%, SwitchPal%, Trans%)
CLS : SCREEN 13
LoadBMP &HA000, 320, 200, "MyPic.BMP", 0, 0, 1, -1
'&HA000 = Video Segment, the segment of the screen
'320 and 200 is the resolution of the videosegment, in screen 13
'"MyPic.BMP" is just a BMP file, must be 256 color
'0, 0 is the top, left location to start drawing the image from
'1 is if it should change the palette to that in the BMP (0 is no)
'-1 is the color to treat as transperent, -1 means all will be drawn
SUB LoadBMP (DestSeg%, SegxRes%, SegyRes%, File$, sX, sY, SwitchPal%, Trans%)
DIM bmp AS BMPHeaderType
f% = FREEFILE
OPEN File$ FOR BINARY AS #f%
GET #f%, , bmp
IF SwitchPal% THEN
pall$ = bmp.Pal
IF LEN(pall$) = 1024 THEN
OUT &H3C8, 0
FOR I% = 1 TO 1024 STEP 4
b% = ASC(MID$(pall$, I%, 1)) \ 4
g% = ASC(MID$(pall$, I% + 1, 1)) \ 4
r% = ASC(MID$(pall$, I% + 2, 1)) \ 4
OUT &H3C9, r%
OUT &H3C9, g%
OUT &H3C9, b%
NEXT I%
END IF
END IF
Byte$ = SPACE$(bmp.WID)
DEF SEG = DestSeg%
wide% = bmp.WID - 1
Hite% = bmp.HEI - 1
offs& = LOC(f) + 1
FOR y% = Hite% TO 0 STEP -1
IF sY + y >= 0 AND sY + y < SegyRes THEN
GET #f%, offs&, Byte$
FOR x% = 0 TO wide%
IF sX + x >= 0 AND sX + x < SegxRes THEN
c% = ASC(MID$(Byte$, x% + 1, 1))
IF c% <> Trans% THEN
POKE (sX% + x%) + (sY% + y%) * (SegxRes + 0&), c%
END IF
END IF
NEXT x%
END IF
offs& = offs& + bmp.WID
NEXT y%
CLOSE #f
DEF SEG
END SUB
Posts: 143
Threads: 35
Joined: Oct 2004
Posts: 1,845
Threads: 44
Joined: Aug 2002
NeoLib comes with a function to load bmps as well.
Posts: 143
Threads: 35
Joined: Oct 2004
do i only have to change the file name? what do i have to change in that code
Posts: 6,419
Threads: 74
Joined: Mar 2002
You don't have to change anything. Just call the sub with the correct parameters (i.e. where you want your image and the filename).
Posts: 143
Threads: 35
Joined: Oct 2004
k it loaded one bmp but the next it was just white screen so i changed the 0,0 but still didnt work. any ideas?
Posts: 3,522
Threads: 189
Joined: Dec 2003
It requires uncompressed standard 8bit BMPs
Make sure to specify the segment, and segment size etc..
Posts: 143
Threads: 35
Joined: Oct 2004
how can i tell if my bmps are uncompressed standard 8bit BMPs ?
Posts: 320
Threads: 9
Joined: Dec 2004
The image editing program you use should let you set some options when you save the bitmap... if it doesn't let you set options, you could assume that it hasn't compressed the bitmap at all.
If you like, you can decompress the compressed images, but it is probably a lot less hassle just to load uncompressed ones. The only form of compression the BMP format supports, as far as I know, is RLE, which is relatively simple.
-shiftLynx
img]http://www.cdsoft.co.uk/misc/shiftlynx.png[/img]
|