I recently received a question from one of my customers, asking how to set the icon for an application (in this case a VCL application). This is something that I’d understood to be trivial, but when I tried it for myself I learned that in fact, it’s more tricky than I’d expected.
[Edit] For iOS icons, see my earlier blog post:
The RAD Studio documentation clearly demonstrates how to set an application icon, however, this is not the problem. The problem is generating a suitable .ico file in the first place. Many image editing software packages do not support exporting to Icon (.ico) format, and when they do, RAD Studio requires a specific type of Icon (.ico) file.
Icon files (.ico) are a container format file, capable of storing multiple images at different resolutions, and in either bitmap (.bmp) or portable network graphics (.png) format. The RAD Studio IDE however expects an icon file to contain only bitmap data.
There are a number of software packages which can be used to create suitable icon files, including:
In this blog post, I’m going to step you through using GIMP to convert an image file (.png in this case) into a suitable icon file for use within a RAD Studio VCL icon.
First, open your file in GIMP.
You can usually do this by right clicking on your image file and selecting “Open with … GNU Image Manipulation Program”, alternatively, open GIMP and select “Open” from the “File” menu.
Now from the GIMP “File” menu, select the “Export AS” option..
In the “Export Image” dialog, expand the “Select by file type” option.
Scroll through and select “Microsoft Windows Icon.”
Note that at the top of the dialog, the file extension has been altered to “.ico”
Click the export button to export your “.ico” file, and then make sure to turn off (un-check) the “Compressed (PNG)” option. In my case I export as “24 bpp, 1-bit alpha, no palette.” I’ve not tried the other options, but I expect them to work. So go ahead and click the “Export” button..
You can now close down the GIMP application as you won’t be needing it any longer. You should find a .ico version of your image file in the same directory that you’d had the original.
Now it’s time to add this to your RAD Studio VCL project.
Open RAD Studio and open your VCL project, then from the “Project” menu, select “Options”…
Click on the “Application” option on the left.
Now click the “Load Icon” button, and browse to your .ico file.
When you click “Open” in the file dialog you’ll be presented with the following..
I don’t think I need to explain these options. Select the most suitable for your project and click “Ok”.
You should now see your icon in the options dialog (in some cases it may not have the correct colors or may appear cropped, it should still be applied correctly to your application when you build it.)
Go ahead and click “Ok” to close the project options dialog, and build your project.
Once you’ve built the project, browse to it using the windows explorer…
You should see that your icon is now correctly applied, though it may appear small in your explorer view. Want to see it close up? Right click your application and select “Send To -> Desktop create shortcut”
And you should now see your icon close up on your desktop.
Thanks for Reading!