▼ |  | File: Racket File and Format Libraries

1 | Convertible: Data-Conversion Protocol
2 | gzip Compression and File Creation
3 | gzip Decompression
4 | zip File Creation
5 | zip File Extraction
6 | tar File Creation
7 | tar File Extraction
8 | tar+gzip File Extraction
9 | MD5 Message Digest
10 | SHA1 Message Digest
11 | GIF File Writing
12 | ICO File Reading and Writing
13 | Windows Registry
14 | Caching
15 | Globbing
| Bibliography
| Index

On this page:

ico?
ico-width
ico-height
ico-depth
ico-format
read-icos
read-icos-from-exe
write-icos
replace-icos
replace-all-icos
ico->argb
ico->png-bytes
argb->ico
png-bytes->ico

top ← prev up next →

### 12`` ICO File Reading and Writing

(require file/ico) | package: base

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). The library also provides support for reading and writing icons in Windows executables.

> > procedure

> > (ico? v) → boolean?

> v : any/c

Returns #t if v represents an icon, #f otherwise.

> > procedure

> > (ico-width ico) → exact-positive-integer?

> ico : ico?

> > procedure

> > (ico-height ico) → exact-positive-integer?

> 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.

Changed in version 6.3 of package base: A PNG-format icon can have a width or height greater than 256.

> > procedure

> > (ico-format ico) → (or/c 'bmp 'png)

> ico : ico?

Reports the format of the icon.

Added in version 6.3 of package base.

> > 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 : path-string?

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 only when the encoding sizes match. Best matches for the existing sizes and depth are drawn from icos (adjusting the scale and depth of a best match as necessary).

Use replace-all-icos, instead, to replace a set of icons wholesale, especially when the set include PNG-format icons.

> > procedure

> > (replace-all-icos icos dest) → void?

> icos : (listof ico?)
> dest : (or/c path-string? output-port?)

Replaces the icon set in the executable dest with the given set of icons.

> > procedure

> > (ico->argb ico) → bytes?

> ico : ico?

Converts an icon in BMP format (see ico-format) 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

> > (ico->png-bytes ico) → bytes?

> ico : ico?

Returns the bytes of a PNG encoding for an icon in PNG format (see ico-format).

Added in version 6.3 of package base.

> > 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 in BMP format.

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

> > procedure

> > (png-bytes->ico bstr) → ico?

> bstr : bytes?

Wraps the given PNG encoding as a PNG-encoded icon.

Added in version 6.3 of package base.

top ← prev up next →