arsd.ico

Load and save support for Windows .ico icon files. It also supports .cur files, but I've not actually tested them yet.

Members

Functions

loadCurFromMemory
IcoCursor[] loadCurFromMemory(const(ubyte)[] data)

Loads a .cur file.

loadIco
MemoryImage[] loadIco(string filename)
loadIcoFromMemory
MemoryImage[] loadIcoFromMemory(const(ubyte)[] data)

Loads a ico file off the given file or from the given memory block.

loadIcoOrCurFromMemoryCallback
void loadIcoOrCurFromMemoryCallback(const(ubyte)[] data, void delegate(int imageType, int numberOfImages) imageTypeChecker, void delegate(MemoryImage mi, int hotspotX, int hotspotY) encounteredImage)

Load implementation. Api subject to change.

writeCur
void writeCur(string filename, IcoCursor[] images)
writeIco
void writeIco(string filename, MemoryImage[] images)
writeIcoOrCur
void writeIcoOrCur(string filename, bool isCursor, int count, IcoCursor delegate(int) getImageAndHotspots)

Save implementation. Api subject to change.

Structs

ICONDIRENTRY
struct ICONDIRENTRY

The icon directory entry of a .ico or .cur file. Note the alignment is not correct for slurping the file.

IcoCursor
struct IcoCursor

A representation of a cursor image as found in a .cur file.

IcoHeader
struct IcoHeader

The header of a .ico or .cur file. Note the alignment is not correct for slurping the file.

Examples

void main() {
	auto thing = loadIco("test.ico");
	import std.stdio;
	writeln(thing.length); // tell how many things it found

	/+ // just to display one
	import arsd.simpledisplay;
	auto img = new SimpleWindow(thing[0].width, thing[0].height);
	{
	auto paint = img.draw();
	paint.drawImage(Point(0, 0), Image.fromMemoryImage(thing[0]));
	}

	img.eventLoop(0);
	+/

	// and this converts all its versions
	import arsd.png;
	import std.format;
	foreach(idx, t; thing)
		writePng(format("test-converted-%d-%dx%d.png", idx, t.width, t.height), t);
}

Meta

History

Written July 21, 2022 (dub v10.9)

Save support added April 21, 2023 (dub v11.0)