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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:14:08+00:00 2026-06-15T06:14:08+00:00

-(CGImageRef)drawing{ CGContextRef context; GLubyte *bitmapData; size_t width, height; width=super.size.width; height=super.size.height; bitmapData = (GLubyte *)

  • 0
-(CGImageRef)drawing{

CGContextRef    context;
GLubyte         *bitmapData;
size_t          width, height;

width=super.size.width;
height=super.size.height;

bitmapData = (GLubyte *) calloc(width * height * 4, sizeof(GLubyte));

context = CGBitmapContextCreate(bitmapData, width, height, 8, width * 4, CGColorSpaceCreateDeviceRGB(), kCGImageAlphaPremultipliedLast);

if (context==NULL){
    NSLog(@"context not created?!   (o_*) ");
}

free(bitmapData);


CGContextSetRGBFillColor (context, 1, 0, 0, 1);
CGContextFillRect (context, CGRectMake (0, 0, 200, 100 ));
CGContextSetRGBFillColor (context, 0, 0, 1, .5);
CGContextFillRect (context, CGRectMake (0, 0, 100, 200 ));




CGImageRef myImage = CGBitmapContextCreateImage (context);

CGContextRelease(context);

return myImage;

}

So i’m trying to render a drawing off screen in a context and then get it as a CGImageRef but for some reason the context is always NULL and the app crashes when i read the image output.

Can someone explain what’s going on here and / or point me to an example where this works.

  • 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-15T06:14:10+00:00Added an answer on June 15, 2026 at 6:14 am

    I don’t know why the context is null – the width & height might be bad.

    But…

    1. You’re freeing the bitmap before you use it!
    2. You can’t release the color space you create.

    There’s an example using CGBitmapContextCreate in the Quartz 2D Programming Guide.

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

Sidebar

Related Questions

I have this code: - (CGImageRef)createImageWithContext:(CGContextRef)context { return CGBitmapContextCreateImage(context); } - (void)fooWithContext:(CGContextRef)context { CGImageRef
In my iPad drawing app, I have a 768 x 1024 buffer context that
I want to create a CGImageRef and draw points to it. What context to
I'm trying to speed up my drawing code. Instead of creating a graphics context,
Is the UIImage method: + (UIImage *)imageWithCGImage:(CGImageRef)imageRef scale:(CGFloat)scale orientation:(UIImageOrientation)orientation cropping the original image or
Going through some documentation on modifying CGImageRef data, I came across a strange example
I added a mask to UIView's layer: CGImageRef maskImageRef = [UIImage imageNamed:Icon.png].CGImage; CALayer maskLayer
I'm trying to get an RGB value of a pixel from a CGImageRef object.
If I use [UIImage imageWithCGImage:] , passing in a CGImageRef , do I then
Here's the code I use to load a texture. image is a CGImageRef. After

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.