Loading icons from files
To load icons from a file, send loadFromFileHandle:atOffset: or loadFromFile: to an instance of the appropriate subclass of CgIconFileFormat. Because the icon file formats allow more than one icon to be stored in a file, these methods answer an array of CgIcon objects if the file was successfully loaded, rather than a single CgIcon object. As with the image file formats, nil is answered if an error occurred. The icon in the array whose size matches the size specified in CgScreen default queryBestIconSize will be answered. If an icon of that size is not found, the first icon in the array is answered.
The following example illustrates how to load the icons from a Windows ICO file named my-icons.ico.
| format icons |
format := CgWinICOFileFormat new.
icons := format
loadFromFile: 'my-icons.ico'.
format hasErrorOccurred
ifTrue: [self error: format currentErrorString].
^icons first
Icons can also be created from png files by sending fromFile: someFilename to the CgIcon class. The following example shows how to create an icon from a png file.
CgIcon fromFile: '$VaRoot\bitmaps\pngfiles\basi3p08.png' where $VaRoot is the Smalltalk install directory.
Furthermore, png files support interlaced frame handlers which the user can supply as smalltalk blocks to capture each interlaced frame as its read.
| frames |
frames := OrderedCollection new.
CgPNGFileFormat new
interlacedFrameHandler: [:img :i :isFinal | frames add: i];
loadFromByteObjects: (Array with: self interlacedPngFile) offsetsIntoByteObjects: (Array with: 0)
 
Last modified date: 11/05/2019