Create a .ico file?

I have all of Christians plugins, so hopefully he will join in here :slight_smile:

So you already have GMImageMBS 


If it’s in the complete plugins, then yes.

I wrote a xojo ICO exporter :stuck_out_tongue:
Ok who’s got a program that can open & show me an ICO file ? (EDIT - Never mind found one and the ICO is just as I wrote it)

Writing them is pretty dead simple except for the patch ups required but even thats not too bad
Not bad for half an hour
http://great-white-software.com/gws-rb-samples/ICO%20writer.zip

[quote=134837:@Norman Palardy]I wrote a xojo ICO exporter :stuck_out_tongue:
Ok who’s got a program that can open & show me an ICO file ? (EDIT - Never mind found one and the ICO is just as I wrote it)

Writing them is pretty dead simple except for the patch ups required but even thats not too bad
Not bad for half an hour
http://great-white-software.com/gws-rb-samples/ICO%20writer.zip[/quote]

Norman, you are the best :slight_smile:

That code actually demo’s 2 techniques

  1. a memoryblock backing a binarystream (which is really handy)


 ummm 


  1. oh yeah writing an ico file :stuck_out_tongue:

There are lots of file formats that are not much different than ICO files (icns etc) and the only real trick is that the directory requires an offset to the item so you have to hang on to that offset and then back patch it before writing everything out

It could probably even be made simpler by just using the memory block size instead of manually tracking the offsets

There is a small issue : the file format is not recognized by Windows :frowning:

opened fine here on my windows 7 & 8 vm’s in paint and greenfish

Thank you so much Norman,
I am sure that will help a lot of users!!!

Maybe because I used one png and one jpeg picture. The pictures were missing in your zip, so I picked whatever I found.

Now reading your code, I realize the picture format and dimensions must count.

What is the expected format of the pictures to use ? I assume their size is 30x30 ?

I thought that a .ico could contain multiple sized images - the same as .icns on OS X???

According to ICO (file format) - Wikipedia it seems possible to have any size.

From what I can gather - Vist supports .ico image sizes up to 256 x 256, but not sure what 7, 8 and now 10 will support?

[quote=134847:@Michel Bujardet]Maybe because I used one png and one jpeg picture. The pictures were missing in your zip, so I picked whatever I found.
[/quote]
Shouldn’t matter as I read whatever images & shove them out as png’s
Sizes can’t be more than 256 x 256 - but thats a limit of the ICO format
Now this code isn’t perfect - far from it
There’s 0 error checking about all kinds of things

It can
That code will let you append a bunch of images then write one ICO

ICO files support up to 256
10 won’t be able to change that without breaking every ICO file
BUT they could use a different format (icon library with the icl suffix) and that could do something different

Thank you so much Norman for spending the time to do that for us all to learn from - very much appreciated :slight_smile:
What kind of error checking should I check for, out of curiosity?

Thanks.

At the very least

  • if you add an image that is larger than the support maximum you should do “something”
  • If the image IS the maximum size (256) then the width or / & height should be set to 0 (they probably are not)
  • if there are no images in it then you should probably not generate any valid header etc (not sure if thats a truly fatal error or not)

stuff like that :slight_smile:

Cool - I will now look into incorporating those checks :slight_smile:
Thank you!

[quote=134861:@Norman Palardy]Shouldn’t matter as I read whatever images & shove them out as png’s
Sizes can’t be more than 256 x 256 - but thats a limit of the ICO format
Now this code isn’t perfect - far from it
There’s 0 error checking about all kinds of things[/quote]

I have now tried under Windows 10. The icon is fine, but the program stumbles in Operator_convert at bs.Close on ioException