<!--
{
  "availability" : [
    "iOS: 9.0.0 -",
    "iPadOS: 9.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.11.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "MetalKit",
  "identifier" : "/documentation/MetalKit/MTKTextureLoader",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "MetalKit"
    ],
    "preciseIdentifier" : "c:objc(cs)MTKTextureLoader"
  },
  "title" : "MTKTextureLoader"
}
-->

# MTKTextureLoader

An object that creates textures from existing data in common image formats.

```
class MTKTextureLoader
```

## Overview

Use the [`MTKTextureLoader`](/documentation/MetalKit/MTKTextureLoader) class to create a Metal texture from existing image data.

This class supports common file formats, like PNG, JPEG, and TIFF. It also loads image data from KTX and PVR files, asset catalogs, Core Graphics images, and other sources. It infers the output texture format and pixel format from the image data.

You create textures synchronously or asynchronously using [`MTKTextureLoader`](/documentation/MetalKit/MTKTextureLoader) methods that return <doc://com.apple.documentation/documentation/Metal/MTLTexture> instances. Pass options to these methods that customize the image-loading and texture-creation process.

First create an [`MTKTextureLoader`](/documentation/MetalKit/MTKTextureLoader) instance, passing the device that it uses to create textures. Then use one of the texture loader’s methods to create a texture. The code example below synchronously creates a texture from data at a URL, using the default options:

```objc
- (id<MTLTexture>)loadTextureUsingMetalKit: (NSURL *) url device: (id<MTLDevice>) device {
    NSError *error;
    MTKTextureLoader *loader = [[MTKTextureLoader alloc] initWithDevice: device];
    
    id<MTLTexture> texture = [loader newTextureWithContentsOfURL:url options:nil error:&error];
    
    if(!texture)
    {
        NSLog(@"Error creating the texture from %@: %@", url.absoluteString, error.localizedDescription);
        return nil;
    }
    return texture;
}
```

If you use custom data formats, or change the image data at runtime, use <doc://com.apple.documentation/documentation/Metal/MTLTexture> methods instead. For more information, see <doc://com.apple.documentation/documentation/Metal/creating-and-sampling-textures>.

## Topics

### Creating a Texture Loader

[`init(device:)`](/documentation/MetalKit/MTKTextureLoader/init(device:))

Initializes a new texture loader object.

[`device`](/documentation/MetalKit/MTKTextureLoader/device)

The device object that the texture loader uses to create textures.

### Loading Textures from URLs

[`newTexture(URL:options:)`](/documentation/MetalKit/MTKTextureLoader/newTexture(URL:options:))

Synchronously loads image data and creates a new Metal texture from a given URL.

[`newTexture(URL:options:completionHandler:)`](/documentation/MetalKit/MTKTextureLoader/newTexture(URL:options:completionHandler:))

Asynchronously loads image data and creates a new Metal texture from a given URL.

[`newTextures(URLs:options:error:)`](/documentation/MetalKit/MTKTextureLoader/newTextures(URLs:options:error:))

Synchronously loads image data and creates new Metal textures from the specified list of URLs.

[`newTextures(URLs:options:completionHandler:)`](/documentation/MetalKit/MTKTextureLoader/newTextures(URLs:options:completionHandler:))

Asynchronously loads image data and creates new Metal textures from the specified list of URLs.

### Loading Textures from Asset Catalogs

[`newTexture(name:scaleFactor:bundle:options:)`](/documentation/MetalKit/MTKTextureLoader/newTexture(name:scaleFactor:bundle:options:))

Synchronously loads image data and creates a Metal texture from the named texture asset in an asset catalog.

[`newTexture(name:scaleFactor:bundle:options:completionHandler:)`](/documentation/MetalKit/MTKTextureLoader/newTexture(name:scaleFactor:bundle:options:completionHandler:))

Asynchronously loads image data and creates a Metal texture from the named texture asset in an asset catalog.

[`newTextures(names:scaleFactor:bundle:options:completionHandler:)`](/documentation/MetalKit/MTKTextureLoader/newTextures(names:scaleFactor:bundle:options:completionHandler:))

Asynchronously loads image data and creates Metal textures from the specified list of named texture assets in an asset catalog.

[`newTexture(name:scaleFactor:displayGamut:bundle:options:)`](/documentation/MetalKit/MTKTextureLoader/newTexture(name:scaleFactor:displayGamut:bundle:options:))

Synchronously loads image data and creates a Metal texture from the named texture asset in an asset catalog, using a specified display gamut.

[`newTexture(name:scaleFactor:displayGamut:bundle:options:completionHandler:)`](/documentation/MetalKit/MTKTextureLoader/newTexture(name:scaleFactor:displayGamut:bundle:options:completionHandler:))

Asynchronously loads image data and creates a Metal texture from the named texture asset in an asset catalog.

[`newTextures(names:scaleFactor:displayGamut:bundle:options:completionHandler:)`](/documentation/MetalKit/MTKTextureLoader/newTextures(names:scaleFactor:displayGamut:bundle:options:completionHandler:))

Asynchronously loads image data and creates Metal textures from the specified list of named texture assets in an asset catalog.

### Loading Textures from Core Graphics Images

[`newTexture(cgImage:options:)`](/documentation/MetalKit/MTKTextureLoader/newTexture(cgImage:options:))

Synchronously loads image data and creates a new Metal texture from a given bitmap image.

[`newTexture(cgImage:options:completionHandler:)`](/documentation/MetalKit/MTKTextureLoader/newTexture(cgImage:options:completionHandler:))

Asynchronously loads image data and creates a new Metal texture from a given bitmap image.

### Loading Textures from In-Memory Data Representations

[`newTexture(data:options:)`](/documentation/MetalKit/MTKTextureLoader/newTexture(data:options:))

Synchronously creates a new Metal texture from an in-memory representation of the texture’s data.

[`newTexture(data:options:completionHandler:)`](/documentation/MetalKit/MTKTextureLoader/newTexture(data:options:completionHandler:))

Asynchronously creates a new Metal texture from an in-memory representation of the texture’s data.

### Loading Textures from Model I/O Representations

[`newTexture(texture:options:)`](/documentation/MetalKit/MTKTextureLoader/newTexture(texture:options:))

Synchronously loads image data and creates a Metal texture from the specified Model I/O texture.

[`newTexture(texture:options:completionHandler:)`](/documentation/MetalKit/MTKTextureLoader/newTexture(texture:options:completionHandler:))

Asynchronously loads image data and creates a Metal texture from the specified Model I/O texture.

### Specifying Loading Options

[`MTKTextureLoader.Option`](/documentation/MetalKit/MTKTextureLoader/Option)

Keys and values used to specify loading options.

### Completing a Texture Loading Operation

[`MTKTextureLoader.ArrayCallback`](/documentation/MetalKit/MTKTextureLoader/ArrayCallback)

The signature for the block executed after an asynchronous loading operation for multiple textures has completed.

[`MTKTextureLoader.Callback`](/documentation/MetalKit/MTKTextureLoader/Callback)

The signature for the block executed after an asynchronous loading operation for a single texture has completed.

### Handling Errors

[`MTKTextureLoader.Error`](/documentation/MetalKit/MTKTextureLoader/Error)

Errors returned by the texture loader.



---

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)