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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T06:46:00+00:00 2026-06-05T06:46:00+00:00

I’m a bit confused about UIGraphicsBeginImageContextWithOptions and threading because according to UIKit Function Reference

  • 0

I’m a bit confused about UIGraphicsBeginImageContextWithOptions and threading because according to UIKit Function Reference UIGraphicsBeginImageContextWithOptions should be called only on the main thread. When called it creates a bitmap-based context, which is ready to be manipulated either with CoreGraphics’ functions or with methods like –drawInRect: for UIImage, -drawInRect:withFont: for NSString and so on. For CoreGraphics’ drawing everything is clear – you pass a CGContextRef argument that is being manipulated to every function, but the UIKit drawing methods use the current context in the stack. In the release notes of What’s New in iOS 4.0 it’s written that

Drawing to a graphics context in UIKit is now thread-safe. Specifically:
– The routines used to access and manipulate the graphics
context can now correctly handle contexts residing on different
threads.
– String and image drawing is now thread-safe.
– Using color and
font objects in multiple threads is now safe to do.

So far so good. The interesting part is that I have a project, where I do some intensive drawings and create multiple images by creating context with UIGraphicsBeginImageContextWithOptions, but when these operations happened to be more time-consuming and I just moved the drawing in a background thread and when ready display them on the screen with some animations and everything works just fine – no crashes, no leaks. Images draw as they are expected and it seems that UIGraphicsBeginImageContextWithOptions creates a context for the background thread and everything seems to be fine.
So my questions are:
– Why it’s necessary to call UIGraphicsBeginImageContextWithOptions only on the main thread as it seems to be working fine in background?
– How to use UIImage‘s -drawInRect: method for example, in a background thread, where I don’t have a current context and I can’t seem be able create one because I can’t call UIGraphicsBeginImageContextWithOptions there?
– What’s is the correct approach to background image manipulation using UIKit’s methods (I know I can also use CGBitmapContextCreate, but it neither pushes the created context into the context stack nor I seem to be able to do it myself in order to use -drawInRect: method of UIImage)?

  • 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-05T06:46:01+00:00Added an answer on June 5, 2026 at 6:46 am

    So, after a couple of days of investigating, how come manipulating the UIKit context is thread-safe and yet you don’t seem to be able to create one in a thread other than the main because UIGraphicsBeginImageContextWithOptions “should be called only on the main thread”, but still doing so works perfectly fine and after reading some small posts on the subject and discussing it with other guys on Apple’s developer forums I can clearly state that, what’s said in the documentation about UIGraphicsBeginImageContextWithOptions, UIGraphicsPushContext and UIGraphicsPopContext is WRONG and those methods could be called and the context used in another thread without problems. So UIGraphicsBeginImageContextWithOptions, UIGraphicsPushContext and UIGraphicsPopContext are thread-safe.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am reading a book about Javascript and jQuery and using one of the
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
I want to construct a data frame in an Rcpp function, but when I
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but

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.