Re: Creating a .icns file again

Alex Zavatone

Do you just need to do this once, or is this a reoccurring thing you need to do while your app is running?

Hmm. I just did this converting PNG images. I’ll take a look.

There also are online resources that may work to provide you with working samples like this one.

Did this work in High Sierra?

On Nov 17, 2018, at 2:55 PM, John Brownie <john_brownie@...> wrote:

I solved this problem in 2012, and then again in 2014, when a change disrupted things. Now Mojave is changing the playing field once more...

The problem:
I need to get the icon for the current keyboard layout and save it in a .icns file, since that's what you have to have.

The old solution:
I get the icon via:
IconRef keyboardIcon = TISGetInputSourceProperty(currentInputSource, kTISPropertyIconRef);

I then get the image representations via:
NSImage *iconImage = [[NSImage alloc] initWithIconRef:keyboardIcon];
NSArray *iconImageReps = [iconImage representations];

The next step is to build a CGImageDestination. The old problem was that CGImageDestinationCreateWithData had a hard limit (undocumented, of course) of 15 images. That limit has apparently now been reduced to 10, only documented by an error message.

Workarounds and the new problem:
My old workaround was to limit it to images smaller than 128x128, which worked. Unfortunately, I now get 36 image representations, and picking 10 doesn't give me enough representations, and I get this message from CGImageDestinationFinalize:
finalize:2477: image destination does not have enough images

The Image I/O documentation says it's no longer being updated, and the last revision date is 2016-09-03. Nothing says that it's deprecated or replaced by something else, as far as I can see.

Am I missing something? Or is there a solution that will actually work?

Thanks for any pointers.
John Brownie
Mussau-Emira language, New Ireland Province, Papua New Guinea
Kouvola, Finland

Join to automatically receive all group messages.