# Get picture of current application icon

**URL:** <https://forum.xojo.com/t/get-picture-of-current-application-icon/25637>\
**Category:** General\
**Created:** [July 22, 2015, 8:54am UTC](https://forum.xojo.com/t/get-picture-of-current-application-icon/25637 "2015-07-22T08:54:18Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hamish\_Symington](https://forum.xojo.com/letter_avatar_proxy/v4/letter/h/6de8d8/32.png) [@Hamish\_Symington](https://forum.xojo.com/u/Hamish_Symington)\
**Post date:** [July 22, 2015, 8:54am UTC](https://forum.xojo.com/t/get-picture-of-current-application-icon/25637/1 "2015-07-22T08:54:18Z")

</div>

Hi -  
I want to display our application’s icon in a few places around it, but I can’t be bothered to update all those other places whenever we update our icon. Is there a way of extracting the picture of our icon (on both Mac and Windows, but happy to use MBS plugins) so all I need to do is update the app icon in the App inspector, and the rest of the places it shows will update themselves?  
Ta  
Hamish

---

<div class="post-metadata">

**Author:** ![Hamish\_Symington](https://forum.xojo.com/letter_avatar_proxy/v4/letter/h/6de8d8/32.png) [@Hamish\_Symington](https://forum.xojo.com/u/Hamish_Symington)\
**Post date:** [July 22, 2015, 9:28am UTC](https://forum.xojo.com/t/get-picture-of-current-application-icon/25637/2 "2015-07-22T09:28:15Z")

</div>

` #if TargetMacOS then
    dim p as picture = app.BundleFolderMBS.IconImageMBS(256)
    p.Mask = app.BundleFolderMBS.IconMaskMBS(256)
  #endif
  #if TargetWin32 then
    dim p as picture = app.ExecutableFile.IconImageMBS(256)
    p.Mask = app.ExecutableFile.IconMaskMBS(256)
  #endif
 `

will do it. But resizing that image gives nasty jagged curves so I’ll need to resize the image myself and save a copy of it.

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [July 22, 2015, 9:28am UTC](https://forum.xojo.com/t/get-picture-of-current-application-icon/25637/3 "2015-07-22T09:28:45Z")

</div>

> [@201840:@Hamish Symington](#):
>
> I want to display our application’s icon in a few places around it, but I can’t be bothered to update all those other places whenever we update our icon. Is there a way of extracting the picture of our icon (on both Mac and Windows, but happy to use MBS plugins) so all I need to do is update the app icon in the App inspector, and the rest of the places it shows will update themselves?

Not the fastest way, but this does get the 1024 x 1024 picture from the dockitem on a Mac.

` dim p as new picture(app.DockItem.Graphics.width, app.DockItem.Graphics.height)
  for x as integer = 0 to app.DockItem.Graphics.width
    for y as integer = 0 to app.DockItem.Graphics.height
      p.RGBSurface.Pixel(x, y) = app.DockItem.Graphics.Pixel(x,y)
    next
  next`

You could do that in a timer to not hold the UI upon launch of the app.

The alternative is to place the picture in your project when you update the app.

---

<div class="post-metadata">

**Author:** ![Hamish\_Symington](https://forum.xojo.com/letter_avatar_proxy/v4/letter/h/6de8d8/32.png) [@Hamish\_Symington](https://forum.xojo.com/u/Hamish_Symington)\
**Post date:** [July 22, 2015, 9:45am UTC](https://forum.xojo.com/t/get-picture-of-current-application-icon/25637/4 "2015-07-22T09:45:11Z")

</div>

There’s a lot of discussion about ways to resize images at [https://forum.xojo.com/9403-scale-quality-of-canvas-control/0](https://forum.xojo.com/9403-scale-quality-of-canvas-control/0) - I’ve chosen to simply make the image at the right size, though.

---

<div class="post-metadata">

**Author:** ![TomE](https://forum.xojo.com/user_avatar/forum.xojo.com/tome/32/583_2.png) [@TomE](https://forum.xojo.com/u/TomE)\
**Post date:** [July 22, 2015, 11:46am UTC](https://forum.xojo.com/t/get-picture-of-current-application-icon/25637/5 "2015-07-22T11:46:05Z")

</div>

Why do you need MBS here? You can get the icon on OS X with one declare (see macoslib).  
Just call “iconForFile” as shown in this Swift line:

```auto
let icon = NSWorkspace().iconForFile("/Users/sample/Desktop/sample.tif")
```

---

<div class="post-metadata">

**Author:** ![Hamish\_Symington](https://forum.xojo.com/letter_avatar_proxy/v4/letter/h/6de8d8/32.png) [@Hamish\_Symington](https://forum.xojo.com/u/Hamish_Symington)\
**Post date:** [July 22, 2015, 12:05pm UTC](https://forum.xojo.com/t/get-picture-of-current-application-icon/25637/6 "2015-07-22T12:05:47Z")

</div>

Sure, I could do it with a declare, too. We’ve got the complete MBS set, that’s all, so don’t mind using it!

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [July 22, 2015, 12:07pm UTC](https://forum.xojo.com/t/get-picture-of-current-application-icon/25637/7 "2015-07-22T12:07:10Z")

</div>

> [@201873:@Hamish Symington](#):
>
> Sure, I could do it with a declare, too. We’ve got the complete MBS set, that’s all, so don’t mind using it!

Besides, MBS works for more than just the Mac.

---

<div class="post-metadata">

**Author:** ![TomE](https://forum.xojo.com/user_avatar/forum.xojo.com/tome/32/583_2.png) [@TomE](https://forum.xojo.com/u/TomE)\
**Post date:** [July 23, 2015, 8:23am UTC](https://forum.xojo.com/t/get-picture-of-current-application-icon/25637/8 "2015-07-23T08:23:19Z")

</div>

Just for the records:  
Define the NSRect struct (x, y, w, h as Single), put the code below in a Canvas Paint event and add your “targetFilePath”:

[code] #pragma Unused areas

dim targetImageSize as Integer = min(g.width, g.height)  
const targetFilePath = “/SAMPLE/PATH/SAMPLE\_FILE”

declare function NSClassFromString lib “Cocoa” (aClassName as CFStringRef) as Ptr  
declare function iconForFile lib “Cocoa” selector “iconForFile:” (obj\_id as Ptr, fullPath as CFStringRef) as Ptr  
declare function sharedWorkspace lib “Cocoa” selector “sharedWorkspace” (class\_id as Ptr) as Ptr  
declare sub CGContextDrawImage lib “Cocoa” (context as Ptr, rect as NSRect, image as Ptr)  
declare function CGImageForProposedRect lib “Cocoa” selector “CGImageForProposedRect:context:hints:” (obj\_id as Ptr, byref proposedDestRect as NSRect, referenceContext as Ptr, hints as Ptr) as Ptr

dim imageRef as MemoryBlock = iconForFile(sharedWorkspace(NSClassFromString(“NSWorkspace”)), targetFilePath)

dim p as new picture(targetImageSize,targetImageSize)  
dim rect As NSRect  
rect.w = targetImageSize  
rect.h = targetImageSize

// Convert the NSImage to CGImage  
dim cntx as Ptr =ptr(p.Graphics.Handle(Graphics.HandleTypeCGContextRef))  
dim cgPtr as Ptr = CGImageForProposedRect( imageRef, rect, nil, nil)

// Draw the CGImage to our Xojo picture  
CGContextDrawImage cntx, rect, cgPtr

g.DrawPicture p, 0, 0  
[/code]

With parts based on [https://forum.xojo.com/18576-how-to-use-nsimage-for-retina-image-handling](https://forum.xojo.com/18576-how-to-use-nsimage-for-retina-image-handling) and [https://forum.xojo.com/13271-nsimage-imagenamed-and-drawing/0](https://forum.xojo.com/13271-nsimage-imagenamed-and-drawing/0) and of course macoslib.

Note: No error checking done here.

---

<div class="post-metadata">

**Author:** ![Michel\_Bujardet](https://forum.xojo.com/user_avatar/forum.xojo.com/michel_bujardet/32/252_2.png) [@Michel\_Bujardet](https://forum.xojo.com/u/Michel_Bujardet)\
**Post date:** [July 23, 2015, 9:28am UTC](https://forum.xojo.com/t/get-picture-of-current-application-icon/25637/9 "2015-07-23T09:28:04Z")

</div>

40209 - All sizes 48 and under missing in icns  
Status: Needs Review Rank: Not Ranked Product: Xojo Category: N/A

Michel Bujardet Today at 11:27 AM  
OS: OS X 10.10.4

Xojo: Xojo 2015r2.2

Steps: There is a big issue going on with icons in Mac builds.

In the project I attached, I placed a picture in each slot of the app icon, with the size of it. For 32 and 16, I made the 8 bit icon in red.

After building, I extracted the icon created by Xojo (attached as App.icns).

When open in Preview (see Preview.png), the 32 and 16 icons are there, but they are just grey. Also, there is only one of each ; no distinction between 32 and 8 bit. I dragged the picture to the finder, it is an empty picture, an invisible background.

I used App WRaper Mini to get a fuller list, in particular to see if Retina support was there. See AppWMini.png. The result is even more worrysome :

All icons 48 and down are incorrect.

- 48 is missing
- 32 and 16 are all simply empty (present but invisible)
- 32 and 16 8 bits are absent.

The only picture with Retina support is the 512 2x (1024).

The icns file itself does not display correctly. It shows up with no icon at all when shown in a list (icns icon missing.png). Makes sense, the 16 x 16 is entirely transparent.

Expected Result:  
all sizes 48 and down contain pictures

Actual Result:  
48 and down are transparent.

\<[https://xojo.com/issue/40209](https://xojo.com/issue/40209)\>

---

<div class="post-metadata">

**Author:** ![Sam\_Rowlands](https://forum.xojo.com/user_avatar/forum.xojo.com/sam_rowlands/32/265_2.png) [@Sam\_Rowlands](https://forum.xojo.com/u/Sam_Rowlands)\
**Post date:** [July 24, 2015, 1:13am UTC](https://forum.xojo.com/t/get-picture-of-current-application-icon/25637/10 "2015-07-24T01:13:57Z")

</div>

If you have the retinaKit you can use the following.

```auto
Dim appIcon as retinaKit.RKPicture = retinaKit.imageNamed( retinaKit.imagename.applicationIcon )
```

Then draw it where you want or even set it as the icon for buttons, menus and so on.

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [October 29, 2020, 5:51pm UTC](https://forum.xojo.com/t/get-picture-of-current-application-icon/25637/11 "2020-10-29T17:51:32Z")

</div>


