0

I have a 2D array of RGB values (assume they are NSColor objects or raw RGB 3-tuples of Doubles), one for each "pixel" of an image I want to draw. To produce the data is expensive so I can't keep running that function often. The data shouldn't be changing at all unless I add a manual function to do so. How do I simply draw it in an NSView?

For such a simple question I am getting swamped by different answers on the internet that aren't quite doing what I want. I started learning how to do this years ago in Obj-C. I just need the more efficient way to move on with my project.

I guess I subclass NSView and assign the class to the view in IB. What now?

Richard Birkett
  • 771
  • 9
  • 20
  • This question is far too broad to be answered in a reasonable way. Is there something you've already tried that didn't work? Perhaps there is a specific problem with regard to what you've already tried that some SO users would be able to help with? – Michael Fourre Jul 25 '17 at 21:03
  • Well I barely know what to try because I can't pick out from the internet what I need. There seem to be millions of methods and I'd rather not read an entire guide about everything on drawing on MacOS. I only need this simple function. I'd even just like to be pointed to the right example. – Richard Birkett Jul 25 '17 at 21:06
  • 1
    How about starting here: https://developer.apple.com/documentation/appkit/nsbitmapimagerep/1395540-initwithbitmapdataplanes?preferredLanguage=occ. – user94559 Jul 25 '17 at 21:10
  • If there are no existing resources available to help you build your solution, then perhaps the desired function is not so simple after all? – Michael Fourre Jul 25 '17 at 21:10
  • 1
    Read this question: https://stackoverflow.com/questions/30958427/pixel-array-to-uiimage-in-swift It creates a `CGImage` from a pixel array, which you can easily convert to `NSImage` for display – Code Different Jul 26 '17 at 02:24
  • So it's working and placed in an NSScrollView but it is horrendously slow to scroll or zoom. I feel this is so inefficient the computer is screaming. I'd rather do the drawing myself pixel by pixel in a custom view. – Richard Birkett Aug 05 '17 at 17:01

0 Answers0