On this page:
ico?
ico-width
ico-height
ico-depth
read-icos
read-icos-from-exe
write-icos
replace-icos
ico->argb
argb->ico

9 ICO File Reading and Writing

 (require file/ico)

The file/ico library provides functions for reading and writing ".ico" files, which contain one or more icons. Each icon is up to 256 by 256 pixels, has a particular depth (i.e., bits per pixel used to represent a color), and mask (i.e., whether a pixel is shown, except that the mask may be ignored for 32-bit icons that have an alpha value per pixel).

procedure

(ico? v)  boolean?

  v : any/c
Returns #t if v represents an icon, #f otherwise.

procedure

(ico-width ico)  (integer-in 1 256)

  ico : ico?

procedure

(ico-height ico)  (integer-in 1 256)

  ico : ico?

procedure

(ico-depth ico)  (one-of/c 1 2 4 8 16 24 32)

  ico : ico?
Returns the width or height of an icon in pixels, or the depth in bits per pixel.

procedure

(read-icos src)  (listof ico?)

  src : (or/c path-string? input-port?)
Parses src as an ".ico" to extract a list of icons.

procedure

(read-icos-from-exe src)  (listof ico?)

  src : (or/c path-string? input-port?)
Parses src as an ".exe" to extract the list of icons that represent the Windows executable.

procedure

(write-icos icos dest [#:exists exists])  void?

  icos : (listof ico?)
  dest : (or/c path-string? output-port?)
  exists : 
(or/c 'error 'append 'update 'can-update
      'replace 'truncate
      'must-truncate 'truncate/replace)
 = 'error
Writes each icon in icos to dest as an ".ico" file. If dest is not an output port, exists is passed on to open-output-file to open dest for writing.

procedure

(replace-icos icos dest)  void?

  icos : (listof ico?)
  dest : (or/c path-string? output-port?)
Writes icons in icos to replace icons in dest as an Windows executable. Only existing icon sizes and depths in the executable are replaced, and best matches for the existing sizes and depth are drawn from icos (adjusting the scale and depth f a best match as necessary).

procedure

(ico->argb ico)  bytes?

  ico : ico?
Converts an icon to an ARGB byte string, which has the icon’s pixels in left-to-right, top-to-bottom order, with four bytes (alpha, red, green, and blue channels) for each pixel.

procedure

(argb->ico width height bstr [#:depth depth])  ico?

  width : (integer-in 1 256)
  height : (integer-in 1 256)
  bstr : bytes?
  depth : (one-of/c 1 2 4 8 24 32) = 32
Converts an ARGB byte string (in the same format as from ico->argb) to an icon of the given width, height, and depth.

The bstr argument must have a length (* 4 width height), and (* width depth) must be a multiple of 8.