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?

6
  • 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? Commented Jul 25, 2017 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. Commented Jul 25, 2017 at 21:06
  • 1
    How about starting here: developer.apple.com/documentation/appkit/nsbitmapimagerep/…. Commented Jul 25, 2017 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? Commented Jul 25, 2017 at 21:10
  • 1
    Read this question: stackoverflow.com/questions/30958427/… It creates a CGImage from a pixel array, which you can easily convert to NSImage for display Commented Jul 26, 2017 at 2:24

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.