This short program will convert a 24/32 bit bitmap into a color data array that can then be used to draw on the screen. I use this quite a bit in my programs since accessing an array is much faster than accessing image data. Do not compile this with -s gui since it uses the console to gather input. You would use the output array in this fashion: (uinteger) pixel = arrayname(x + y * bmpwidth). Real world example: prch = parch(x + y * parchw), where prch is a uniteger, x and y are the pixel coordinates, and parchw is the bitmap width.
It might be useful for someone.
'Convert.bas
'Richard Clark
'Extracts the color information from a 24/32 bit bitmap
'to an include file for use in an FB program.
'Using a graphic screen and the Point function.
'Do not compile with -s gui, as this uses the console screen
'for input.
'Public doman, use any way you like.
dim as integer iw, ih, sw, sh, dp = 32
dim as string iname, aname, oname
dim as integer x, y, i, fh, cnt
Input "Enter bitmap width";iw
if iw = 0 then iw = 256
Input "Enter bitmap height";ih
if ih = 0 then ih = 256
Input "Enter bitmap filename (including extension)";iname
Input "Enter data array name";aname
Input "Enter export file name (including extension ex: pic.bi)";oname
Input "Enter graphic screen width";sw
if sw = 0 then sw = 640
Input "Enter graphic screen height";sh
if sh = 0 then sh = 480
if iw <= 0 or ih <= 0 then
print "Width and height must be greater than zero."
sleep
end
end if
if len(iname) = 0 or len(aname) = 0 or len(oname) = 0 then
print "No values given for filename, array name or output file name."
sleep
end
end if
if sw <= 0 or sh <= 0 or dp <= 0 then
print "Screen dimensions and depth must be greater than zero."
sleep
end
end if
if len(dir(iname)) = 0 then
print "Cannot find " & iname &"."
sleep
end
end if
fh = freefile
if open(oname for output as #fh) <> 0 then
print "Cannot open output file."
sleep
end
end if
dim bmvals(iw * ih) as uinteger
screenres sw, sh, dp
if Screenptr = 0 then
print "Cannot set graphic screen."
sleep
close fh
end
end if
bload iname
'Print out header information
Print #fh, "'Useage: (uinteger) pixel = ";aname; "(x + y * ";aname & "w)"
print #fh, "Const ";Trim(aname);"w = ";Str(iw)
print #fh, "Const ";trim(aname);"h = ";Str(ih)
print #fh, "Dim Shared " & trim(aname) & "(" & str(iw * ih) & ") As UInteger = { _"
for x = 0 to iw - 1
for y = 0 to ih - 1
bmvals(x + y * iw) = point(x, y)
next
next
for i = lbound(bmvals) to ubound(bmvals)
cnt += 1
if i = ubound(bmvals) then
print #fh, "&h" & hex(bmvals(i)) & "}"
else
if cnt < 8 then
print #fh, "&h" & hex(bmvals(i)) & ",";
else
print #fh, "&h" & hex(bmvals(i)) & ", _"
cnt = 0
end if
end if
next
close fh
end