---
title: "QLPreviewRequestCreateContext(_:_:_:_:)"
framework: quicklook
role: symbol
role_heading: Function
path: "quicklook/qlpreviewrequestcreatecontext(_:_:_:_:)"
---

# QLPreviewRequestCreateContext(_:_:_:_:)

Creates a graphics context to draw the preview in.

## Declaration

```swift
func QLPreviewRequestCreateContext(_ preview: QLPreviewRequest!, _ size: CGSize, _ isBitmap: Bool, _ properties: CFDictionary!) -> Unmanaged<CGContext>!
```

## Parameters

- `preview`: The preview request object.
- `size`: The size of the preview; if isBitmap is true the size is in pixels, otherwise it’s in points.
- `isBitmap`: true if the preview uses a bitmap-based graphics context, false otherwise. This value of this parameter affects the interpretation of the size parameter.
- `properties`: A dictionary containing properties for the preview response. Preview Properties lists the current property keys and describes their values.

## Return Value

Return Value A Core Graphics graphics-context object that you can draw your preview image in. You should explicitly release this object when it is no longer needed.

## Discussion

Discussion You can directly draw your preview data in the graphics-context object created by this function. After calling this function, you should flush the context with QLPreviewRequestFlushContext(_:_:). Also be sure to release the CGContext object. Quick Look provides three types of graphics contexts for drawing previews: bitmap, single-page vector-based, and multi-page vector-based (for PDF previews). You use this function to acquire a context for bitmap and single-page vector drawing; the isBitmap parameter is used to distinguish between them. For multi-page contexts, use the QLPreviewRequestCreatePDFContext(_:_:_:_:) function. If you prefer to work in Objective-C code, you can convert the created CGContext to a NSGraphicsContext object using init(graphicsPort:flipped:). Special Considerations Thread-safety: This function should be called in the same thread as the preview request is made in; generally, this is the same thread in which the GeneratePreviewForURL callback was invoked.

## See Also

### Requesting previews

- [QLPreviewRequestCopyContentUTI(_:)](quicklook/qlpreviewrequestcopycontentuti(_:).md)
- [QLPreviewRequestCopyOptions(_:)](quicklook/qlpreviewrequestcopyoptions(_:).md)
- [QLPreviewRequestCopyURL(_:)](quicklook/qlpreviewrequestcopyurl(_:).md)
- [QLPreviewRequestCreatePDFContext(_:_:_:_:)](quicklook/qlpreviewrequestcreatepdfcontext(_:_:_:_:).md)
- [QLPreviewRequestFlushContext(_:_:)](quicklook/qlpreviewrequestflushcontext(_:_:).md)
- [QLPreviewRequestGetDocumentObject(_:)](quicklook/qlpreviewrequestgetdocumentobject(_:).md)
- [QLPreviewRequestSetDocumentObject(_:_:_:)](quicklook/qlpreviewrequestsetdocumentobject(_:_:_:).md)
- [QLPreviewRequestGetGeneratorBundle(_:)](quicklook/qlpreviewrequestgetgeneratorbundle(_:).md)
- [QLPreviewRequestGetTypeID()](quicklook/qlpreviewrequestgettypeid().md)
- [QLPreviewRequestIsCancelled(_:)](quicklook/qlpreviewrequestiscancelled(_:).md)
- [QLPreviewRequestSetDataRepresentation(_:_:_:_:)](quicklook/qlpreviewrequestsetdatarepresentation(_:_:_:_:).md)
- [QLPreviewRequestSetURLRepresentation(_:_:_:_:)](quicklook/qlpreviewrequestseturlrepresentation(_:_:_:_:).md)
