public void saveAsIco(OutputStream out) throws IOException {
		byte[] buffer = new byte[16];
		int count = 0;
		int[] sizes = new int[] { 256, 128, 64, 48, 32, 16 };
		for (int size : sizes) {
			if (hasImage(size)) {
				count++;
			}
		}
		EndianUtils.writeLEShort(0, buffer, 0);
		EndianUtils.writeLEShort(1, buffer, 2);
		EndianUtils.writeLEShort(count, buffer, 4);
		out.write(buffer, 0, 6);
		int totalImageBytes = 0;
		List<byte[]> images = new ArrayList<>();
		for (int size : sizes) {
			if (hasImage(size)) {
				buffer[0] = (byte) (size == 256 ? 0 : size);
				buffer[1] = buffer[0];
				buffer[2] = 0;
				buffer[3] = 0;
				EndianUtils.writeLEShort(1, buffer, 4);
				EndianUtils.writeLEShort(32, buffer, 6);
				ByteArrayOutputStream baos = new ByteArrayOutputStream();
				if (!StdImage.writePNG(baos, getImage(size), 72)) {
					throw new IOException(UNABLE_TO_CREATE_PNG);
				}
				byte[] bytes = baos.toByteArray();
				images.add(bytes);
				EndianUtils.writeLEInt(bytes.length, buffer, 8);
				EndianUtils.writeLEInt(6 + buffer.length * count + totalImageBytes, buffer, 12);
				out.write(buffer);
				totalImageBytes = bytes.length;
			}
		}
		for (byte[] bytes : images) {
			out.write(bytes);
		}
	}