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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T18:21:41+00:00 2026-05-30T18:21:41+00:00

Ive been trying to work with UIGraphicsGetCurrentContext and CGContextRef. I was told that using

  • 0

Ive been trying to work with UIGraphicsGetCurrentContext and CGContextRef. I was told that using UIGraphicsGetCurrentContext() numerous times is bad and to rather work on using CGContextRef and referring to it.

I have been trying to work on the second part and I am having issues setting the @property and referring to it. Can someone give me a declaration and usage example of this? Tried googling and couldn’t find any references to it.

Ta

  • 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-30T18:21:43+00:00Added an answer on May 30, 2026 at 6:21 pm

    You probably shouldn’t store the return value from UIGraphicsGetCurrentContext in a property. You usually either don’t know how long the context will be valid, or the context has a short lifetime anyway. For example, if you’re calling UIGraphicsGetCurrentContext from your drawRect: method, you don’t know how long that context will survive after you return from drawRect:. If you’re calling UIGraphicsGetCurrentContext after calling UIGraphicsBeginImageContextWithOptions, you will probably be calling UIGraphicsEndImageContext soon anyway. It would be inappropriate to keep references to those contexts around.

    If you are calling many Core Graphics functions on the same context, then you want to store the context in a local variable. For example, here is a drawRect: method from one of my test projects:

    - (void)drawRect:(CGRect)dirtyRect {
        NSLog(@"drawRect:%@", NSStringFromCGRect(dirtyRect));
        [self layoutColumnsIfNeeded];
        CGContextRef gc = UIGraphicsGetCurrentContext();
        CGContextSaveGState(gc); {
            // Flip the Y-axis of the context because that's what CoreText assumes.
            CGContextTranslateCTM(gc, 0, self.bounds.size.height);
            CGContextScaleCTM(gc, 1, -1);
            for (NSUInteger i = 0, l = CFArrayGetCount(_columnFrames); i < l; ++i) {
                CTFrameRef frame = CFArrayGetValueAtIndex(_columnFrames, i);
                CGPathRef path = CTFrameGetPath(frame);
                CGRect frameRect = CGPathGetBoundingBox(path);
                if (!CGRectIntersectsRect(frameRect, dirtyRect))
                    continue;
    
                CTFrameDraw(frame, gc);
            }
        } CGContextRestoreGState(gc);
    }
    

    You can see that I’m doing a bunch of stuff with the context: I’m saving and restoring the graphics state, I’m changing the CTM, and I’m drawing some Core Text frames into it. Instead of calling UIGraphicsGetCurrentContext many times, I call it just once and save the result in a local variable named gc.

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

Sidebar

Related Questions

I've been trying to understand how Ruby blocks work, and to do that I've
I've been trying to get colourschemes to work properly in VIM when using it
I've been trying to work with the Google Calendar JSON API, but have been
I've been trying to work this out for 2 days now and I have
I've been trying to work with the Yahoo Contacts API using the latest version
I have been trying to load my pre-filled database into my device, ive tried
Im currently trying to work the imageSnapshot function in flex. Ive been looking hard
Here's the code that I've been trying to work with: $.getJSON(http://api.remix.bestbuy.com/v1/products(search= + escape(searchCriteria) +
Ive been trying to get this sql statement to work properly through excel vba.
I have been trying everything I can to get this script to work and

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.