When I try to import any .ico file, I get the following error
IcNames = FileNames[{"*.ico"}, "c:\\Users\\gal\\Documents\\D0\\ikone\\"];
Import[IcNames[[26]] ]
How to fix it?
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityIt looks like Mathematica's importer for .ico files doesn't implement the latest standard. Specifically, it doesn't support images in PNG format. Luckily, PNG files are embedded in their entirety, so it is quite straightforward to patch the .ico importer to support PNG files:
Quiet@ImportString["", "ICO"];
Begin["System`Convert`ICODump`"];
Once[
DownValues@`ImportIconResource = DownValues@`ImportIconResource /.
w_Which :> If[`width == 169478669,
SetStreamPosition[`strm, Last@`entry];
`data = ImportByteArray[ByteArray@BinaryReadList[`strm, "Byte", `entry[[-2]]], "PNG"];
Sow[ImageData@`data, "Data"];
Sow[ImageDimensions@`data, "ImageSize"],
w
];
]
End[];
This works by patching the relevant definition System`Convert`ICODump`ImportIconResource
:
width
) since the first 4 are discarded, but since width
should never be bigger than 256, this shouldn't pose any issues.ImportByteArray
, and interpret it as a PNG.
Import["ExampleData/mathematica3.ico"]
? What version of Mathematica are you running? $\endgroup$