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 8089777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T19:30:42+00:00 2026-06-05T19:30:42+00:00

Very simple question… I have an array of pixels, how do I display them

  • 0

Very simple question… I have an array of pixels, how do I display them on the screen?

#define WIDTH 10
#define HEIGHT 10
#define SIZE WIDTH*HEIGHT

unsigned short pixels[SIZE];

for (int i = 0; i < WIDTH; i++) {
    for (int j = 0; j < HEIGHT; j++) {
        pixels[j*HEIGHT + i] = 0xFFFF;
    }
}

That’s it… now how can I show them on the screen?

  • 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-06-05T19:30:43+00:00Added an answer on June 5, 2026 at 7:30 pm
    1. Create a new “Cocoa Application” (if you don’t know how to create a cocoa application go to Cocoa Dev Center)
    2. Subclass NSView (if you don’t know how to subclass a view read section “Create the NSView Subclass”)
    3. Set your NSWindow to size 400×400 on interface builder
    4. Use this code in your NSView

      #import "MyView.h"
      
      @implementation MyView
      
      #define WIDTH 400
      #define HEIGHT 400
      #define SIZE (WIDTH*HEIGHT)
      #define BYTES_PER_PIXEL 2
      #define BITS_PER_COMPONENT 5
      #define BITS_PER_PIXEL 16
      
      - (id)initWithFrame:(NSRect)frame
      {
          self = [super initWithFrame:frame];
          if (self) {
              // Initialization code here.
          }
          return self;
      }
      
      - (void)drawRect:(NSRect)dirtyRect
      {
          // Get current context
          CGContextRef context = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
      
          // Colorspace RGB
          CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
      
          // Pixel Matrix allocation
          unsigned short *pixels = calloc(SIZE, sizeof(unsigned short));
      
          // Random pixels will give you a non-organized RAINBOW 
          for (int i = 0; i < WIDTH; i++) {
              for (int j = 0; j < HEIGHT; j++) {
                  pixels[i+ j*HEIGHT] = arc4random() % USHRT_MAX;
              }
          }
      
          // Provider
          CGDataProviderRef provider = CGDataProviderCreateWithData(nil, pixels, SIZE, nil);
      
          // CGImage
          CGImageRef image = CGImageCreate(WIDTH,
                                           HEIGHT,
                                           BITS_PER_COMPONENT,
                                           BITS_PER_PIXEL,
                                           BYTES_PER_PIXEL*WIDTH,
                                           colorSpace,
                                           kCGImageAlphaNoneSkipFirst,
                                           // xRRRRRGGGGGBBBBB - 16-bits, first bit is ignored!
                                           provider,
                                           nil, //No decode
                                           NO,  //No interpolation
                                           kCGRenderingIntentDefault); // Default rendering
      
      // Draw
      CGContextDrawImage(context, self.bounds, image);
      
      // Once everything is written on screen we can release everything
      CGImageRelease(image);
      CGColorSpaceRelease(colorSpace);
      CGDataProviderRelease(provider);
      
      }
      @end
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Very simple question I am sure. I have a file called ACLReader.vbs which I
i have a very simple question... i am using the SDL API which was
very simple question: I have admin site in my web project. So, how can
Very simple question: suppose I have the following js/jquery code doSomething(); $.get(url, callback); doSomethingElse();
very simple question (but I can't find the answer on the Web...): I have
A very simple question. I have a .war(~40MB) file to be run on JBoss.
I have a very simple question (I guess!) How can clone method be protected
I have a very simple question and would be great if someone could save
very simple question, i have this: $datos1=mysql_query(SELECT TIMEDIFF(NOW(), ' . $row['fecha'] . ');); echo($datos1);
Very simple question I hope. I have the usual <select> box like this <select

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.