Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6118151
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:24:10+00:00 2026-05-23T15:24:10+00:00

In my Mac application, I am letting the user paint on a grid, each

  • 0

In my Mac application, I am letting the user paint on a grid, each square on the grid representing a pixel and having its own colour. Is it possible to then take that colour and simple one by one produce an image by setting the pixel colour?

I can’t really think of how else to do this. I need to export an image once the user has painted into this grid that I am making.

Thanks.

The aim of my app:
The user can paint into a grid. So the final image might be 16×16 pixels in size, however the user in the app can paint each pixel into a square of a grid (16×16). This is then outputted into the format of the final image which might be 16×16 pixels, literally on screen. While the grid visually while painting is larger. Each square on the grid represents a pixel in the final image, and the user can put a single colour into each square. Hopefully this makes sense, if not I shall try and elaborate and link an example.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T15:24:11+00:00Added an answer on May 23, 2026 at 3:24 pm

    [TLDR: Use Model-View-Controller.]

    There are three distinct things to consider here:

    1. The “ideal” image that the user is drawing, a grid of 16×16 (or however many) coloured pixels.
    2. The onscreen representation of it, where each pixel is displayed at much larger size for the user to interact with.
    3. An eventual image file exported from the app.

    Keeping those elements separate in your mind and your implementation will make your life a lot easier.

    #1 is a model, and in this case will likely consist of an array of 256 (or however many) colour values, probably along with some descriptive data like the pixel dimensions and colour space. For something this simple you might not want to create a separate model class (although you should), but even if it’s just an array ivar sitting in a monolithic app class you should still think of it as a distinct entity in its own right.

    #2 is a view (with controller tendencies), and you should almost certainly implement it using a custom NSView subclass. It would be possible to build a grid of 256 instances of NSColorWell or some other existing NSView type, but that would just be silly. The view has two jobs:

    1. Draw the model onscreen. Do this by iterating over the data values and drawing each one as a filled rectangle of an appropriate size. The methods of NSBezierPath are your friends here, especially the class methods fillRect and strokeRect.
    2. Mediate user input. For example, you might decide that the user colours a pixel by clicking on it with the mouse. Your view will get sent an event for each mouse click, and will need to respond by mapping the click location to the correct pixel (basically a matter of division) and then making the appropriate changes to the model.

    #3 is in some ways just another kind of view, in that it is another way of representing the model. Code for producing it is sometimes included with the model (say if there’s only one canonical way of serialising the data), but it’s good practice to put it somewhere else, especially if you might want to add other arbitrary mechanisms later.

    The key here is that this image is really nothing to do with the NSView side of things, it’s a matter of taking the model data and writing it out. You can do the writing via NSImage methods or via Core Graphics, as mentioned in the other answers, but what you absolutely shouldn’t do is try to manhandle it directly off the screen. That way lies madness!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am having some troubles to use iCloud within my mac application. Following what
I'm developing a mac application in C++, and I'm having the following problem: words(26222,0xa0b5c540)
I'm porting Chicken of VNC Mac application into iphone application I am having source
As part of a Mac application I am working on, the user fills out
I have a Core Data based mac application that is working perfectly well until
I'm trying to link my mac application to the wonderful libancillary library. However, I
How can I access/remove PNG metadata? I'm looking for a Mac application or a
I'm updating application for Mac OS X 10.6 and getting this error. I believe
I'm writing an application for Mac OS X 10.6 and later in C++. One
I have an application for Mac OS X that supports plugins that are intended

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.