<!--
{
  "availability" : [
    "iOS: 4.0.0 - 27.0.0",
    "iPadOS: 4.0.0 - 27.0.0",
    "macCatalyst: 13.1.0 - 27.0.0",
    "tvOS: -",
    "visionOS: 1.0.0 - 27.0.0",
    "watchOS: 2.0.0 - 27.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "UIKit",
  "identifier" : "/documentation/UIKit/UIGraphicsBeginImageContextWithOptions(_:_:_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "UIKit"
    ],
    "preciseIdentifier" : "c:@F@UIGraphicsBeginImageContextWithOptions"
  },
  "title" : "UIGraphicsBeginImageContextWithOptions(_:_:_:)"
}
-->

# UIGraphicsBeginImageContextWithOptions(_:_:_:)

Creates a bitmap-based graphics context with the specified options.

```
func UIGraphicsBeginImageContextWithOptions(_ size: CGSize, _ opaque: Bool, _ scale: CGFloat)
```

## Parameters

`size`

The size (measured in points) of the new bitmap context. This represents the size of the image returned by the [`UIGraphicsGetImageFromCurrentImageContext()`](/documentation/UIKit/UIGraphicsGetImageFromCurrentImageContext()) function. To get the size of the bitmap in pixels, you must multiply the width and height values by the value in the `scale` parameter.

`opaque`

A Boolean flag indicating whether the bitmap is opaque. If you know the bitmap is fully opaque, specify <doc://com.apple.documentation/documentation/Swift/true> to ignore the alpha channel and optimize the bitmap’s storage. Specifying <doc://com.apple.documentation/documentation/Swift/false> means that the bitmap must include an alpha channel to handle any partially transparent pixels.

`scale`

The scale factor to apply to the bitmap. If you specify a value of `0.0`, the scale factor is set to the scale factor of the device’s main screen.

## Discussion

You use this function to configure the drawing environment for rendering into a bitmap. The format for the bitmap is a ARGB 32-bit integer pixel format using host-byte order. If the opaque parameter is <doc://com.apple.documentation/documentation/Swift/true>, the alpha channel is ignored and the bitmap is treated as fully opaque (<doc://com.apple.documentation/documentation/CoreGraphics/CGImageAlphaInfo/noneSkipFirst> | <doc://com.apple.documentation/documentation/CoreGraphics/kCGBitmapByteOrder32Host>). Otherwise, each pixel uses a premultipled ARGB format (<doc://com.apple.documentation/documentation/CoreGraphics/CGImageAlphaInfo/premultipliedFirst> | <doc://com.apple.documentation/documentation/CoreGraphics/kCGBitmapByteOrder32Host>).

The environment also uses the default coordinate system for UIKit views, where the origin is in the upper-left corner and the positive axes extend down and to the right of the origin. The supplied scale factor is also applied to the coordinate system and resulting images. The drawing environment is pushed onto the graphics context stack immediately.

While the context created by this function is the current context, you can call the [`UIGraphicsGetImageFromCurrentImageContext()`](/documentation/UIKit/UIGraphicsGetImageFromCurrentImageContext()) function to retrieve an image object based on the current contents of the context. When you are done modifying the context, you must call the [`UIGraphicsEndImageContext()`](/documentation/UIKit/UIGraphicsEndImageContext()) function to clean up the bitmap drawing environment and remove the graphics context from the top of the context stack. You should not use the [`UIGraphicsPopContext()`](/documentation/UIKit/UIGraphicsPopContext()) function to remove this type of context from the stack.

In most other respects, the graphics context created by this function behaves like any other graphics context. You can change the context by pushing and popping other graphics contexts. You can also get the bitmap context using the [`UIGraphicsGetCurrentContext()`](/documentation/UIKit/UIGraphicsGetCurrentContext()) function.

This function may be called from any thread of your app.

## See Also

[`UIGraphicsEndImageContext()`](/documentation/UIKit/UIGraphicsEndImageContext())

Removes the current bitmap-based graphics context from the top of the stack.

[`UIGraphicsGetImageFromCurrentImageContext()`](/documentation/UIKit/UIGraphicsGetImageFromCurrentImageContext())

Returns an image from the contents of the current bitmap-based graphics context.



---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)