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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:05:22+00:00 2026-05-27T01:05:22+00:00

I have the following code: CGContextRef ctx = UIGraphicsGetCurrentContext(); UIGraphicsBeginImageContext(size); screenImageContext = UIGraphicsGetCurrentContext(); ctx

  • 0

I have the following code:

CGContextRef ctx = UIGraphicsGetCurrentContext();
UIGraphicsBeginImageContext(size);
screenImageContext = UIGraphicsGetCurrentContext();
ctx = screenImageContext;

UIGraphicsPushContext(UIGraphicsGetCurrentContext());
ctx  = UIGraphicsGetCurrentContext();

NSLog(@" %@",screenImageContext);
UIImage * result = UIGraphicsGetImageFromCurrentImageContext(); // Returns nil

UIImageWriteToSavedPhotosAlbum(result, nil, nil, nil);

UIGraphicsPopContext();
result = UIGraphicsGetImageFromCurrentImageContext(); // returns valid result

My problem is that UIGraphicsGetImageFromCurrentImageContext returns nil, while the second one after UIGraphicsPopContext returns the correct result.

The docs clearly states that UIGraphicsGetImageFromCurrentImageContext will return nil when either the context is nil or the current context isn’t a graphic context, but both these problems aren’t happening here.

If anyone could shed some light over this i’d be very grateful
Shai.

  • 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-27T01:05:22+00:00Added an answer on May 27, 2026 at 1:05 am

    From my understanding of things your issue is stemming from the following line

    UIGraphicsPushContext(UIGraphicsGetCurrentContext());
    

    With this call you’re trying to make the current context the current context. This really doesn’t make any sense.

    Also with your code it’s a little scrambled, you call UIGraphicsGetCurrentContext() which will return the current context, then you call UIGraphisBeginImageContext(CGSize size) which as stated in the doc’s

    Creates a bitmap-based graphics context and makes it the current context

    Then you get the current graphics context again which is now a bitmap-based graphics context thanks to the previous call, then you overwrite the original CGContextRef (“ctx”) that you just retrieved.

    I’m not 100% certain what you were aiming to achieve with your code but if you were just trying to capture the contents of a bitmap-based context in an image and save it to the photo album then the following code will do that.

    CGSize size = CGSizeMake(320, 480); //Screen Size on iPhone device
    UIGraphicsBeginImageContext(size);  //Create a new Bitmap-based graphics context (also makes this the current context)
    CGContextRef screenImageContext = UIGraphicsGetCurrentContext(); //get a reference to the context we just made above
    NSLog(@" %@",screenImageContext);
    //NOTE: without any drawring code in here this will just be a blank image (white/alpha)
    // or an image set to whatever the current UIColor is set to
    //So you may want to add some drawing code in here. Although TBH I'm not sure what you were originally
    // trying to achieve.
    UIImage * result = UIGraphicsGetImageFromCurrentImageContext(); // Returns nil
    NSLog(@" %@",result); //just output this to demonstrate that it's non null/nil
    UIImageWriteToSavedPhotosAlbum(result, nil, nil, nil);
    UIGraphicsEndImageContext(); //Removes the current bitmap-based graphics context from the top of the stack
    

    Hope that helps.

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

Sidebar

Related Questions

I have the following code snippet CGContextRef ctx = UIGraphicsGetCurrentContext(); CGColorRef color = CreateDeviceRGBColor(r,g,b,a);
I have following code: Tools::Logger.Log(string(GetLastError()), Error); GetLastError() returns a DWORD a numeric value, but
I have following code: mQuestions=DictionaryDbWrapper.getInstance().getQuestionsSequence( this.getIntent().getStringExtra(ApplicationUtilities.TEST_CATEGORY_PARAMETER), 50); mQuestionsCount=mQuestions.size(); Log.e(count, String.valueOf(mQuestionsCount)); if (mQuestionsCount==0) { Log.e(1,
I Have following code: Controller: public ActionResult Step1() { return View(); } [AcceptVerbs(HttpVerbs.Post)] public
I have following Code Block Which I tried to optimize in the Optimized section
I have following code in my application: // to set tip - photo in
I have following code in my Application. Comments in my code will specify My
I have following code in my application. [self.navigationController pushViewController:x animated:YES]; It will push a
I have following code class User attr_accessor :name end u = User.new u.name =
i have following code to show div on page <div id=all_users> <div id=user11 userid=11

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.