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

  • Home
  • SEARCH
  • 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 8732537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:27:27+00:00 2026-06-13T09:27:27+00:00

I would like to keep the memory block allocated in the function void ManipulateImagePixelData(CGImageRef

  • 0

I would like to keep the memory block allocated in the function void ManipulateImagePixelData(CGImageRef inImage) (see http://developer.apple.com/library/mac/#qa/qa1509/_index.html for the complete code)

void ManipulateImagePixelData(CGImageRef inImage)
{
    // Create the bitmap context
    CGContextRef cgctx = CreateARGBBitmapContext(inImage);
    if (cgctx == NULL) 
    { 
        // error creating context
        return;
    }

     // Get image width, height. We'll use the entire image.
    size_t w = CGImageGetWidth(inImage);
    size_t h = CGImageGetHeight(inImage);
    CGRect rect = {{0,0},{w,h}}; 

    // Draw the image to the bitmap context. Once we draw, the memory 
    // allocated for the context for rendering will then contain the 
    // raw image data in the specified color space.
    CGContextDrawImage(cgctx, rect, inImage); 

    // Now we can get a pointer to the image data associated with the bitmap
    // context.
    void *data = CGBitmapContextGetData (cgctx);
    if (data != NULL)
    {

        // **** You have a pointer to the image data ****

        // **** Do stuff with the data here ****

    }

    // When finished, release the context
    CGContextRelease(cgctx); 
    // Free image data memory for the context
    if (data)
    {
        free(data);
    }

}

I have modified the function so that I have the width and height, but I don’t manage to get the memory block data points to.

My function looks like:

void ManipulateImagePixelData(CGImageRef inImage, 
unsigned long * width, unsigned long * height, void * copy)

I no longer free data at the end and take the responsability of freeing it later.

I thought I could do something simple like this:

(caller)
 void * rawPixels=NULL;
ManipulateImagePixelData([obj CGImageForProposedRect:NULL context:[NSGraphicsContext currentContext] hints:nil],&imgWidth1, &imgHeight1, rawPixels)];


(ManipulateImagePixelData function)
void * pixels = CGBitmapContextGetData (cgctx);
    if (pixels != NULL) {
    *width=w;
    *height=h;
    copy=pixels;
    [...]

And have rawPixels point to the aforementioned block, but rawPixels is still NULL after this call. I’m a bit confused by this and my C skills are a bit rusty.

What should I do to get the data ?

  • 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-13T09:27:29+00:00Added an answer on June 13, 2026 at 9:27 am

    You should pass into ManipulateImagePixelData a pointer to the variable where you would like to get the address of the buffer allocated within the function:

    void ManipulateImagePixelData(CGImageRef inImage, unsigned long * width, unsigned long * height, void ** copy) {
    
            ...
            void* data = CGBitmapContextGetData (cgctx);
            *copy = data; // copy the output parameter
            ...
    }  
    

    and call it like this:

    void * rawPixels=NULL;
    ManipulateImagePixelData([obj CGImageForProposedRect:NULL context:[NSGraphicsContext currentContext] hints:nil],&imgWidth1, &imgHeight1, &rawPixels)];
    

    Better yet, you could define it like this:

    void* ManipulateImagePixelData(CGImageRef inImage, unsigned long * width, unsigned long * height) {
    
              ...
              void* data = CGBitmapContextGetData (cgctx);
              ...
              return data;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am implementing a logging function and I would like to keep track of
I have a large bitmap that i would like to keep in memory when
I have ~10,000 records would like to keep in a collection in memory and
I have a Go object whose address in memory I would like to keep
I would like to keep first link as default selected with javascript, here is
I would like to keep model binding when doing ajax calls from my view.
I would like to keep an item selected, on a ListView, when the user
Requirements I would like to keep an audit log of particular events, such as:
I have a small JSF app and would like to keep some state on
I'm playing with bencoding and I would like to keep bencoded strings as Java

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.