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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:56:07+00:00 2026-05-22T17:56:07+00:00

I have a simple drawing issue. I have prepared a 2 dimensional array which

  • 0

I have a simple drawing issue. I have prepared a 2 dimensional array which has an animated wave motion. The array is updated every 1/10th of a second (this can be changed by the user). After the array is updated I want to display it as a 2 dimensional image with each array value as a pixel with color range from 0 to 255.

Any pointers on how to do this most efficiently…

Appreciate any help on this…

KAS

  • 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-22T17:56:08+00:00Added an answer on May 22, 2026 at 5:56 pm

    If it’s just a greyscale then the following (coded as I type, probably worth checking for errors) should work:

    CGDataProviderRef dataProvider =
           CGDataProviderCreateWithData(NULL, pointerToYourData, width*height, NULL);
    
    CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceGray();
    CGImageRef inputImage = CGImageCreate(  width, height,
                                            8, 8, width, 
                                            colourSpace, 
                                            kCGBitmapByteOrderDefault,
                                            dataProvider,
                                            NULL, NO,
                                            kCGRenderingIntentDefault);
    CGDataProviderRelease(dataProvider);
    CGColorSpaceRelease(colourSpace);
    
    UIImage *image = [UIImage imageWithCGImage:inputImage];
    CGImageRelease(inputImage);
    
    someImageView.image = image;
    

    That’d be for a one-shot display, assuming you didn’t want to write a custom UIView subclass (which is worth the effort only if performance is a problem, probably).

    My understanding from the docs is that the data provider can be created just once for the lifetime of your C buffer. I don’t think that’s true of the image, but if you created a CGBitmapContext to wrap your buffer rather than a provider and an image, that would safely persist and you could use CGBitmapContextCreateImage to get a CGImageRef to be moving on with. It’s probably worth benchmarking both ways around if it’s an issue.

    EDIT: so the alternative way around would be:

    // get a context from your C buffer; this is now something
    // CoreGraphics could draw to...
    CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceGray();
    CGContextRef context = 
            CGBitmapContextCreate(pointerToYourData,
                                  width, height,
                                  8, width,
                                  colourSpace,
                                  kCGBitmapByteOrderDefault);
    CGColorSpaceRelease(colourSpace);
    
    // get an image of the context, which is something
    // CoreGraphics can draw from...
    CGImageRef image = CGBitmapContextCreateImage(context);
    
    /* wrap in a UIImage, push to a UIImageView, as before, remember
       to clean up 'image' */
    

    CoreGraphics copies things about very lazily, so neither of these solutions should be as costly as the multiple steps imply.

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

Sidebar

Related Questions

in a simple drawing application I have a model which has a NSMutableArray curvedPaths
I have a simple OpenGL drawing. When the user changes the window's size, I
This should be so simple, but I'm drawing a blank. I have two tables.
I have simple issue setting a two-way databinding of a checkbox in Silverlight 3.0.
I have simple SSIS package which reads data from flat file and insert into
I have simple SSIS package in which On Error event handler I have created
I have a VB6 application (please don't laugh) which does a lot of drawing
I have a prototype of a simple drawing application. When the user drags a
I have a simple Form such as the following: using System; using System.Drawing; using
Suppose you have to create a simple 2D animation, like the drawing of a

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.