The program can then be posted to the forum to allow the generation of a bitmap from data statements.
I have provided such programs to generate images for another program posted on the forum that uses them.
Probably the bitmap shouldn't be more than 32 pixels wide keeping in mind you will end up with long data statements.
Also the more colors the larger the resulting palette colors() generated.
Before running the program enter the file name of the bitmap to be converted to data statements and the file name of the resulting bitmap to be saved as. Also you can choose the name of the resulting program that will create the bitmap from the data statements.
Code: Select all
Const NULL As Any Ptr = 0
screenres 640,480,32
dim shared as string fileName,fileName2,progName
fileName = "thumbsUp.bmp" ' <----- change to desired bitmap to load
fileName2 = "thumbsUp2.bmp" ' <----- change to desired name of save
progName = "createThumbsUp2.bas" ' <----- change to desired name of program created
dim shared as any ptr image
dim shared as integer iWidth,iHeight
sub loadImage(file as string)
dim as integer fileHnd = FreeFile()
'get width and height of bitmap
open file for binary as #fileHnd
get #fileHnd, 19, iWidth
get #fileHnd, 23, iHeight
close #fileHnd
'initialize pointers to pic.i bitmaps
image = imagecreate(iWidth,iHeight,rgb(255,255,255))
bload file,image 'bload bitmap pic.i
If image = NULL Then
Print "image creation failed!"
Sleep
End
end if
end sub
loadImage(fileName)
'=========== NOW EXTRACT COLOR PALETTE INTO colors LIST =======
dim shared as ulong colors(100000)
dim shared as ulong v
dim shared as integer totalColors,found
for j as integer = 0 to iHeight-1
for i as integer = 0 to iWidth - 1
v = point(i,j,image) 'get a color
found = 0
if totalColors > 0 then 'search for color
for i as integer = 0 to totalColors-1
if colors(i)= v then 'color found
found = 1
end if
next i
end if
if found=0 then 'not found so add to list
colors(totalColors) = v
totalColors = totalColors + 1
end if
next i
next j
'=====================================================
dim as ubyte r,g,b
Open progName For Output As #1
print #1,"screenres 640,480,32"
print #1,"dim as any ptr image"
print #1,"image = imagecreate(";iWidth;",";iHeight;")"
print #1,"dim as ulong colors(";totalColors;")"
for i as integer = 0 to totalColors-1
v = colors(i)
r = v shr 16 and 255
g = v shr 8 and 255
b = v and 255
print #1,"colors(";i;")=RGB(";r;",";g;",";b;")"
next i
print #1, " dim as integer n"
print #1, " for j as integer = 0 to ";iHeight-1
print #1, " for i as integer = 0 to ";iWidth-1
print #1, " read n"
print #1, " pset image,(i,j),colors(n)"
print #1, " next i"
print #1, " next j"
print #1, "bsave ";chr(34);filename2;chr(34);",image"
print #1,
'============== now make sprite data statements =======================
dim as integer c 'palette number
dim as integer charCount
dim as string sn 'to remove leading space
for j as integer = 0 to iHeight-1
charCount = 0
print #1, "DATA ";
for i as integer = 0 to iWidth-1
if i<>0 then print #1,",";
v = point(i,j,image)
'find color in list and get palette number c
for n as integer = 0 to totalColors-1
if v = colors(n) then
c=n
end if
next n
sn = str(c)
print #1,sn;
charCount = charCount + len(sn)
if charCount > 50 then
charCount = 0
print #1,"_"
end if
next i
print #1,
next j
print #1,
Close #1
print
print "A program called createBitMap.bas has been created"
print "If you load and run this program it will create"
print "and save the image as a file called"; fileName2
sleep