Recent

Author Topic: How to extract icons from files on OSX?  (Read 2773 times)

MISV

  • Hero Member
  • *****
  • Posts: 711
How to extract icons from files on OSX?
« on: March 09, 2015, 01:00:46 pm »
If I want to get application icon of an executable (coming from Windows, so may be the wrong term) - how do I do this on OSX?

If I want to get the default icon for e.g. ".html" files how do I do that?

I used to use Windows API for this - I have tried Google, but did not find any solution for OSX


kamischi

  • Full Member
  • ***
  • Posts: 177
Re: How to extract icons from files on OSX?
« Reply #1 on: March 09, 2015, 01:37:18 pm »
I do not think that there is a system wide and general definition of these icons. I did not really check, but my assumption is that it is defined in the program, which is declared to be the standard application for that kind of file. Since the program can change, the icon may also change. I would expect the icon for html files in Safari.
fpc 2.6.4, lazarus 1.4.0, Mac OS X, fink

skalogryz

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 2546
    • havefunsoft.com
Re: How to extract icons from files on OSX?
« Reply #2 on: March 09, 2015, 04:24:59 pm »
IIRC, there's a code in either LCL of FPCRes manager to write and well as extract icon files from .icns.

.icns could be found in a bundle (.app) directory.

.icns is a very simple storage file that just keeps all images together.
Images 64x64 has a simple bitmap-like format. Images larger than 64x64 are just PNGs.

If you need to extract an application of an arbitrary bundle, you should first inspect the bundles info.plist file. It actually points to the .icns file name (if multiple .icns) file is present.

Also, NSImage (cocoa) and CGImage (CoreGraphics, works in Carbon) should be to read the file and extract it as bitmap or convert it to any other desired format.
« Last Edit: March 09, 2015, 04:29:39 pm by skalogryz »
Patron Cocoa Widgetset development https://www.patreon.com/skalogryz

 

TinyPortal © 2005-2018