putting a .bmp at point (x,y)

Please use this Board for QBasic related requests ( file research, programming, etc.)

Moderators:Administrator, Global Moderator

Post Reply
Guest
putting a .bmp at point (x,y)

Post by Guest » Wed Nov 27, 2002 5:09 am

i was wondering if someone could tell me how to load a .bmp file at the coordinates (x,y)
any help would be appreciated

User avatar
frankiebaby
Global Moderator
Posts:95
Joined:Tue Apr 30, 2002 1:38 am
Location:Pennsylvania
Contact:

Re: putting a .bmp at point (x,y)

Post by frankiebaby » Thu Nov 28, 2002 6:15 pm

Well, i really dont know anything much about bitmaps, but i do know there are code snippets out there, in the ABC packets, on websites, ect, that will do that for you.
I have used bitmaps in qbasic before, and the process always looks long, and almost always requires you to change the palette to match the bmp or else have strange or slightly off colors. Heres one by Kim Christensen, that I use. I comment out the pallete changing part, and so if ya use mspaint, blue and red are swapped. as well as yellow and teal.

Code: Select all

'By Kim Christensen
'This routine will read in a Windows Bitmap file and display it.
'Only 16 color Bitmaps are supported. Even with SCREEN 13: I am
'only using that mode to "blow up" the picture a bit.
'Comments? Questions? Suggestions? : uv317@freenet.victoria.bc.ca
'No flames please! :)

INPUT "Filename"; data$
IF LTRIM$(RTRIM$(data$)) = "" THEN END
OPEN data$ FOR BINARY AS #1
IF LOF(1) = 0 THEN PRINT "File not found!": CLOSE : KILL data$: END

table$ = INPUT$(54, #1)  'Get the file header (54 bytes)
DIM table&(30)           'Create numerical array for header
DEF SEG = VARSEG(table&(1))
pointer% = VARPTR(table&(1))

'Poke the data from string "table$" into numerical array "table&"
FOR x% = 0 TO 51
 POKE pointer% + x%, ASC(MID$(table$, x% + 3, 1))
NEXT
DEF SEG

'Check for valid file type
IF MID$(table$, 1, 2) <> "BM" OR table&(4) <> 40 THEN
 &nbsp; PRINT "Not a valid *.BMP file!": END
END IF
IF table&(8) <> 0 THEN
 &nbsp; PRINT "This program will not diplay RLE encoded files": END
END IF
IF ASC(MID$(table$, 29, 1)) <> 4 THEN
 &nbsp; PRINT "Only 16 color bitmaps are supported!": END
END IF

'Set the video mode for best picture fit
IF (table&(5) < 321) AND (table&(6) < 201) THEN
 &nbsp; SCREEN 13
ELSE
 &nbsp; SCREEN 12
END IF
LOCATE 2, 1
PRINT " Image is "; table&(5); " by "; table&(6)

thecolors$ = INPUT$(table&(3) - 54, #1) 'Read in pallette info
DEF SEG = VARSEG(pal&)
pointer% = VARPTR(pal&)
Poke the pallette info from the string "thecolors$"
into pal& and reduce to 6 bits per byte.
FOR x% = 0 TO 63 STEP 4
 POKE pointer%, (ASC(MID$(thecolors$, x% + 3, 1))) \ 4
 POKE pointer% + 1, (ASC(MID$(thecolors$, x% + 2, 1))) \ 4
 POKE pointer% + 2, (ASC(MID$(thecolors$, x% + 1, 1))) \ 4
 POKE pointer% + 3, 0
PALETTE x% \ 4, pal&
NEXT
DEF SEG

'Read in Bitmap data and set pixels accordingly
y% = table&(6) 'Put number of vertical pixels into y%
DO
 &nbsp;data$ = INPUT$((((table&(5) - 1) OR 7) + 1) \ 2, #1)
 &nbsp; &nbsp;IF (table&(5) \ 2) < LEN(data$) THEN
 &nbsp; &nbsp; &nbsp; linelength% = table&(5) \ 2
 &nbsp; &nbsp;ELSE
 &nbsp; &nbsp; &nbsp; linelength% = LEN(data$)
 &nbsp; &nbsp;END IF
 &nbsp; &nbsp;FOR x% = 1 TO linelength%
 &nbsp; &nbsp; &nbsp;pixel% = ASC(MID$(data$, x%, 1))
 &nbsp; &nbsp; &nbsp;PSET (x% * 2 + 1, y%), pixel% AND 15
 &nbsp; &nbsp; &nbsp;PSET (x% * 2, y%), pixel% \ 16
 &nbsp; &nbsp;NEXT
 &nbsp; &nbsp;y% = y% - 1
LOOP UNTIL EOF(1) OR INKEY$ <> ""

Post Reply