Correct way to display icns icon of apps with transparency

When I’m reading icon of an application, I got this weird white background around the icon when the background is black. Any way to avoid that?

Using IconMBS from Monkeybread software.

Screen Shot 2023-02-05 at 10.49.15

Code is

pic.Transparent = 1
g.DrawPicture pic, 0, 0, pic.Width / 2, pic.Height/2, 0, 0, pic.Width, pic.Height

Don’t use transparent = 1. That’s a carryover from the old days when only a single color could be transparent and it’s setting it to only use black. If you remove that code, it will probably work better

If I remove the code, the dark background is not displayed.

Here the full code without transparency. Trying to have a dark background on dark mode and full transparency of the icon on the canvas

If pic <> Nil Then
  g.ClearRectangle(0, 0, g.Width, g.Height)
  If Color.IsDarkMode = True then
    g.DrawingColor = &c000000 //&cffffff
    g.DrawingColor =  &cffffff
  End If
  g.FillRectangle(0, 0, g.Width, g.Height)
  Dim p As Picture
  g.DrawPicture pic, 0, 0, pic.Width / 2, pic.Height/2, 0, 0, pic.Width, pic.Height
End If

Does that work? If not, let’s see another screenshot.

It’s not working. In dark mode, the background of the canvas stay white.
Screen Shot 2023-02-05 at 17.44.58

You should add a breakpoint and make sure the icon images have an alpha channel because it looks like they don’t.

How do you get the icons?

Private Function getApplicationIcon(EmailClient as String) As Picture
  if SupportedEmailClients = Nil then
    SupportedEmailClients = new SupportedMailApps
  end if
  dim BundleID as String = SupportedEmailClients.GetBundleIDForClient(EmailClient)
  dim theApp as FolderItem = LaunchServicesFindApplicationForInfoMBS("", BundleID,"")
  if theApp = nil then Return Nil
  dim theNSImage as NSImageMBS = NSWorkspaceMBS.iconForFile(theApp)
  if theNSImage = Nil then Return Nil
  theNSImage.size = new NSSizeMBS(LBAccounts.RowHeight - 2 * IconOffset, LBAccounts.RowHeight - 2 * IconOffset)
  dim AppImage as Picture = theNSImage.CopyPictureWithMask
  Return AppImage
End Function

Seems like you’ve possibly got two problems here, the icon transparency and the background color of the canvas.

I suggest you force the canvas to fill itself with black, so you can check that your icons are working correctly. Then you can come back to the white canvas background question.

I was using iconMBS but even with your code, cannot get a transparent icon.

Dim p As Picture
if f.Exists then
  //p = f.IconMBS(w)
  p = getApplicationIcon(f)

Transparent = 1 was a great command line. Why Xojo is now making it more complicated?

The old Transparent value only let you specify a single color to be transparent - so your icons had to have a bright green background, for example, that would turn transparent. But because it is only a single color turning transparent, icons would have sharp, jagged edges - real transparency requires feathered edges, with some pixels showing partial transparency.

The old system dates back to Mac System 8 and 9, and whatever Windows version. Newer operating systems have moved far beyond those limited graphics imaging systems.