This is an open source 32bit png to ico converter, which supports 8 bit alpha values! Just drag pngs onto the exe, and an icon will be created in the same folder.
It should support multiple icons per ico file, but they're not working at the moment
global dim split$(-1) as string
split(cl$())
global dim width(array count(split$(0)))
global dim height(array count(split$(0)))
global dim depth(array count(split$(0)))
global icocount
icocount = array count(split$(0))+1
for af = 0 to array count(split$(0))
filename$ = split$(af)
if file exist(filename$)
load image filename$,af+1,1
else
exit prompt "Image does not exist: "+cl$(),"Error 1"
end
endif
make memblock from image af+1,af+1
delete image af+1
width(af) = memblock dword(af+1,0)
height(af) = memblock dword(af+1,4)
depth(af) = memblock dword(af+1,8)
next af
`Header
type icoheader
idReserved as Word
idType as Word
idCount as Word
endtype
type icoentry
bWidth as Byte `; (* Width *)
bHeight as Byte `; (* Height *)
bColorCount as Byte `; (* Nr. of colors used, see below *)
bReserved as Byte `; (* not used, 0 *)
wPlanes as Word `; (* not used, 0 *)
wBitCount as Word `; (* not used, 0 *)
dwBytesInRes as integer `; (* total number of bytes in images *)
dwImageOffset as integer `;(* location of image from the beginning of file *)
endtype
type bmpHeader
biSize as integer `; (* sizeof(TBitmapInfoHeader *)
biWidth as integer `; (* width of bitmap *)
biHeight as integer `; (* height of bitmap, see notes *)
biPlanes as Word `; (* planes, always 1 *)
biBitCount as Word `; (* number of color bits *)
biCompression as integer `; (* compression used, 0 *)
biSizeImage as integer `; (* size of the pixel data, see notes *)
biXPelsPerMeter as integer `; (* not used, 0 *)
biYPelsPerMeter as integer `; (* not used, 0 *)
biClrUsed as integer `; (* nr of colors used, set to 0 *)
biClrImportant as integer `; (* important colors, set to 0 *)
endtype
header as icoheader
header.idReserved = 0
header.idType = 1
header.idCount = icocount
dim icons(icocount-1) as icoentry
global foffset
foffset = (icocount*16)+6
for af = 0 to icocount-1
icons(af).bWidth = width(af)
icons(af).bHeight = height(af)
icons(af).bColorCount = 0
icons(af).bReserved = 0
icons(af).wPlanes = 1
icons(af).wBitCount = 32
icons(af).dwBytesInRes = (width(af)*height(af)*4)+((width(af)*height(af))/8)+40
icons(af).dwImageOffset = foffset
inc foffset,icons(af).dwBytesInRes
next af
dim image(icocount-1) as bmpHeader
for af = 0 to icocount-1
image(af).biSize = 40
image(af).biWidth = width(af)
image(af).biHeight = height(af)*2
image(af).biPlanes = 1
image(af).biBitCount = 32
image(af).biCompression = 0
image(af).biSizeImage = (width(af)*height(af)*4)+((width(af)*height(af))/8)
image(af).biXPelsPerMeter = 0
image(af).biYPelsPerMeter = 0
image(af).biClrUsed = 0
image(af).biClrImportant = 0
next af
open to write 1,split$(0)+"_.ico"
`header
write word 1,header.idReserved
write word 1,header.idType
write word 1,header.idCount
`icons
for af = 0 to icocount-1
write byte 1,icons(af).bWidth
write byte 1,icons(af).bHeight
write byte 1,icons(af).bColorCount
write byte 1,icons(af).bReserved
write word 1,icons(af).wPlanes
write word 1,icons(af).wBitCount
write long 1,icons(af).dwBytesInRes
write long 1,icons(af).dwImageOffset
next af
for af = 0 to icocount-1
`images
write long 1,image(af).biSize
write long 1,image(af).biWidth
write long 1,image(af).biHeight
write word 1,image(af).biPlanes
write word 1,image(af).biBitCount
write long 1,image(af).biCompression
write long 1,image(af).biSizeImage
write long 1,image(af).biXPelsPerMeter
write long 1,image(af).biYPelsPerMeter
write long 1,image(af).biClrUsed
write long 1,image(af).biClrImportant
`XOR image data
make memblock icocount+1,get memblock size(af+1)-12
copy memblock af+1,icocount+1,12,0,get memblock size(icocount+1)
delete memblock af+1
temp as dword
for y = 1 to height(af)/2
y2 = (height(af)+1)-y
for x = 1 to width(af)
temp = memblock dword(icocount+1,((y-1)*width(af)*4)+((x-1)*4))
write memblock dword icocount+1,((y-1)*width(af)*4)+((x-1)*4),memblock dword(icocount+1,((y2-1)*width(af)*4)+((x-1)*4))
write memblock dword icocount+1,((y2-1)*width(af)*4)+((x-1)*4),temp
next x
next y
write memblock 1,icocount+1
make memblock af+1,get memblock size(icocount+1)/32
write memblock 1,af+1
delete memblock af+1
delete memblock icocount+1
next af
close file 1
end
function split(txt$)
inq = 0
l = len(txt$)
for d = 1 to l
if mid$(txt$,d) = chr$(34)
inq = 1-inq
endif
if mid$(txt$,d) = " " and inq = 0
array insert at top split$(0)
split$(0) = trim$(left$(txt$,d-1),chr$(34))
txt$ = right$(txt$,l-(d-1))
dec l,d
d = 1
endif
next d
array insert at top split$(0)
split$(0) = trim$(txt$,chr$(34)+" ")
endfunction
The two sites I used to get the info:
site1 site2
If anyone can tell me why its not working for multiple icons per ico file I would be very grateful!