Images, camera, and photos

Display existing images and photos, create or capture new images, and read and write image data.

Choose the best file formats for images

Include images to make your app more compelling, and effectively convey ideas and information. You can incorporate bitmap or vector-based images into your app in many ways. Use images in buttons, toolbars, and other views to reduce the amount of text in your app, which saves space and minimizes translation costs. In other parts of your interface, add images to convey ideas or add visual flair. To personalize someone’s experience, you can even incorporate images from their photo library into your interface with their permission

Build your interface from system-provided images whenever possible, and store other custom images your app requires in its bundle directory. If you create or capture new images in your app, store them in your app’s container directory or ask the person to choose a storage location.

Choose the best file formats for images

Apple platforms support a wide assortment of image formats, including common formats like PNG, JPEG, GIF, TIFF, HEIC, camera RAW, and many others. Apple also offers SF Symbols, a library of vector- based images you can use in your apps. When creating images for your app, choose the format best suited for the intended task:

  • Prefer SF Symbols for images you assign to buttons, toolbars, and other views in your interface. Symbols come in multiple weights, scale readily, and you can tint them to match your content. The SF Symbols library contains more than 6,900 symbols, and you can Creating custom symbols using the SF Symbols app.

  • Use the PNG format for bitmap images you include in your interface. Apple platforms handle PNG images more efficiently than many other file formats.

  • Store images you create on disk using the HEIC (High Efficiency Image Container) file format. This format offers smaller sizes than JPEG files while maintaining a high level of quality and efficiency.

One of the benefits of using Apple technologies to load images is you don’t have to know anything about the image format. The image types in Image, UIImage, and NSImage automatically detect image formats using a combination of filename extensions and file data, and transform the image data into a usable image object. You can read and write image data yourself if you prefer using the Image I/O framework, but typically only do so for advanced image manipulations. For example, you might use that framework to read exposure information, timestamp details, and other image-specific metadata.

Load images and photos from disk

The platform-provided image types handle most of the heavy lifting required to load and prepare images for display. Use the Image, UIImage, and NSImage types to load images from an Managing assets with asset catalogs, Bundle directory, on-disk location, or from image data you create. You can also use these types to load an SF Symbols or other system-provided image. The following listing shows the code you use to create an image type and initialize it with an existing image.

After you create an image type, display it in your app’s interface using an image view for Image, UIImageView, or NSImageView. Although you can draw images using custom drawing code, an image view is a more efficient option and handles many types of changes for you. For example, an image view can toggle between Providing images for different appearances of an image automatically.

Retrieve and display someone’s personal photos

People view and manage personal photos in the Photos app on their device. Apps can also request access to someone’s photos and incorporate them into the content that person creates. For example, a social media app might let someone add their personal photos to their feed. To requestAuthorization(for:handler:) and Fetching Objects and Requesting Changes someone’s personal photos, use PhotoKit. You can also use PhotoKit to:

Capture photos and video from an available camera

Another way to integrate photos and videos into your app is to capture them using the device’s camera. On supported devices, you can display the system’s capture interface to obtain new images or video content. The interface offers a preview of the image along with controls to capture it. The use of a system-provided interface protects the person’s privacy while still giving you the images you need.

If you’re building a UIKit app, display the UIImagePickerController view controller to present the standard system interface. This interface runs out-of-process and offers options to select an existing photo or capture a new one.

When you need more control over the capture process, build a custom capture interface and use the AVFoundation framework to manage the Setting up a capture session. Use your custom interface to capture Photo capture or Audio and video capture, and capture content in a variety of Capturing photos in RAW and Apple ProRAW formats and Recording movies in alternative formats formats. You can even capture Capturing photos with depth on devices that support it, and use depth values to separate foreground and background content in the image.

If you define a custom capture interface, make it more widely available by providing a Creating a camera experience for the Lock Screen. This app extension is a widget that people can add to the Lock Screen, Control Center, or Action button of their iPhone or iPad. Interacting with the widget launches your app’s experience, giving them a way to capture photos and videos without navigating to your app first.

The AVFoundation framework can capture content from a variety of externally connected devices, but you can also access those devices directly using the ImageCaptureCore framework. You might use it to connect to a ICCameraDevice, ICScannerDevice, or other media device and communicate with it directly. For example, you might download existing photos and videos from the device, or use the device to capture new photos or videos.

Read and write image data directly

For most images, you’ll use the built-in image types to load and and manage the image data. However, when you want to CGImageSource and CGImageDestination image data yourself, you can do so using the types of the Image I/O framework. These types support a CGImageSourceCopyTypeIdentifiers(), and make it easier to get the data you need. You can also use this framework to create Creating spatial photos and videos with spatial metadata for Apple Vision Pro.

Modern cameras often put metadata inside images, including exposure settings, timestamps, camera details, and even the location where the person took the picture. Use the CGImageSource type to retrieve this metadata as a dictionary of properties, including:

Create new images programmatically

In addition to using images in your interface, you can create images programmatically from your app. For example, someone using a drawing app might export an image of their artistic creation so they can share it online. A word processor app might turn someone’s document-based content into a PDF file. You might even generate images of your own app’s interface and use them in custom transition effects.

The Core Graphics framework contains many of the fundamental types you use to generate images, and is available on all platforms. The App design and UI frameworks also offer convenient ways to create new images. Use the following types to generate new images: