<!--
{
  "availability" : [
    "iOS: 2.0.0 -",
    "iPadOS: 2.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.0.0 -",
    "tvOS: -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "CoreGraphics",
  "identifier" : "/documentation/CoreGraphics/CGDataProvider/init(filename:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Core Graphics",
      "CoreGraphics"
    ],
    "preciseIdentifier" : "c:@F@CGDataProviderCreateWithFilename"
  },
  "title" : "init(filename:)"
}
-->

# init(filename:)

Creates a direct-access data provider that uses a file to supply data.

```
init?(filename: UnsafePointer<CChar>)
```

## Parameters

`filename`

The full or relative pathname to use for the data provider. When you supply Core Graphics data via the provider, it reads the data from the specified file.

## Return Value

A new data provider or `NULL` if the file could not be opened. In Objective-C, you’re responsible for releasing this object using [`CGDataProviderRelease`](/documentation/CoreGraphics/CGDataProviderRelease).

## Discussion

You use this function to create a direct-access data provider that supplies data from a file. When you supply Core Graphics with a direct-access data provider, Core Graphics obtains data from your program in a single block.

---

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)