Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Extract the icons stored into an "ico" file

Usefull Functions & Procedures

Extract the icons stored into an "ico" file

by  vgulielmus  Posted    (Edited  )
An "ico" file usually contains more than a single icon (icons with different resolution / number of colors)
The following function extract the icons stored from a "ico" file into separate files (each icon into its own file), and can be used for "cur" files as well

[code Foxpro]LOCAL lcFName,lcFContent,lnIcoNo,lni,lcExtrIco,lnBytes,lnOffset

lcFName = GETFILE("ICO;CUR")
IF EMPTY(m.lcFName)
RETURN "No file"
ENDIF
lcFContent = FILETOSTR(m.lcFName)
IF LEFT(m.lcFContent,2) <> CHR(0) + CHR(0)
RETURN "No valid Ico file"
ENDIF

IF !INLIST(SUBSTR(m.lcFContent,3,2) , CHR(1) + CHR(0) , CHR(2) + CHR(0))
RETURN "No valid Ico file"
ENDIF

lnIcoNo = CTOBIN(SUBSTR(m.lcFContent,5,2),'RS')
FOR lni = 1 TO m.lnIcoNo
lcExtrIco = LEFT(m.lcFContent,4) + CHR(1) + CHR(0)
lnBytes = CTOBIN(SUBSTR(m.lcFContent,7 + 8 + 16 * (m.lni-1),4),'RS')
lnOffset = CTOBIN(SUBSTR(m.lcFContent,7 + 12 + 16 * (m.lni-1),4),'RS')
lcExtrIco = m.lcExtrIco + SUBSTR(m.lcFContent,7 + 16 * (m.lni-1),12) + CHR(0x16) + CHR(0) + CHR(0) + CHR(0)
lcExtrIco = m.lcExtrIco + SUBSTR(m.lcFContent,1 + m.lnOffset, m.lnBytes)
STRTOFILE(m.lcExtrIco,FORCEEXT('ico'+TRANSFORM(m.lni)+SYS(2015),JUSTEXT(m.lcFName)))
NEXT
RETURN TRANSFORM(m.lnIcoNo) + " files generated"[/code]

http://en.wikipedia.org/wiki/ICO_%28file_format%29

Vilhelm-Ion Praisach
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top