-1

Very simple: How to programatically create transparent NSImage? Unless it is not so simple... Previous OSX versions gave NSImage transparent background by default when calling

let image = NSImage(size: size)

but now it has black background. How do I create a transparent one? I want to lockFocus() on atransparent image of given size it and and draw.

Rasto
  • 17,204
  • 47
  • 154
  • 245

1 Answers1

1

A few major Mac OS versions ago the lock/unlock focus methods, while not deprecated, have been deemphasized in favor of NSImage(size:flipped:drawingHandler:) for deferred drawing. I have personally encountered problems with unexpectedly-rasterized text and certain alpha channel problems when composing multiple images together into one using lock/unlock in apps linked against later macOS SDKs.

My first suggestion would be to use that method and see if that resolves the issue. Your drawing handler can simply contain return true.

Joshua Nozzi
  • 60,946
  • 14
  • 140
  • 135
  • Was your issue where you were doing different types of compositing on one image...I'm having the strangest outputs. – Chris Aug 13 '18 at 13:38
  • @Chris Not sure if compositing had anything specifically to do with it, but as I said, the biggest problem was that text was always rasterized. It's been awhile so I can't remember exactly the problem with alpha but I believe it was probably text background issues. – Joshua Nozzi Aug 13 '18 at 18:09