Skip to content
DeveloperMemos

The Difference Between HEIF and HEIC

HEIF, HEIC, Image Format2 min read

When it comes to storing and displaying images on mobile devices, developers often encounter various file formats. Two popular image formats that have gained traction in recent years are HEIF (High Efficiency Image Format) and its successor HEIC (High Efficiency Image Container). These formats offer advanced compression techniques and improved image quality compared to traditional formats like JPEG and PNG. In this article, we'll delve into the differences between HEIF and HEIC and discuss their significance in Android and iOS development.

HEIF: The High Efficiency Image Format

HEIF, short for High Efficiency Image Format, is an image container format developed by the MPEG group. It leverages the High Efficiency Video Coding (HEVC) compression algorithm to achieve smaller file sizes while maintaining high-quality images. HEIF supports a wide range of features, including:

  • Static images
  • Image sequences
  • Animation
  • Metadata storage
  • Lossless and lossy compression

With the ability to store multiple images, along with their associated metadata, in a single file, HEIF provides a more efficient way of managing and sharing images. However, due to limited hardware and software support, widespread adoption of HEIF was initially slow.

HEIC: The HEIF Image Container

HEIC, which stands for High Efficiency Image Container, is a specific implementation of the HEIF format commonly used for still images. Developed by Apple, HEIC files have the file extension ".heic" and are widely supported on iOS devices. HEIC offers several advantages over other image formats, including:

  1. Smaller File Sizes: HEIC provides better compression compared to JPEG while maintaining similar or better image quality. This enables users to store more images without consuming excessive storage space.

  2. Improved Image Quality: HEIC supports a wider color gamut and higher dynamic range, resulting in more vibrant and detailed images.

  3. Rich Metadata: HEIC files can store extensive metadata, including location information, editing history, and more. This metadata enhances the overall user experience by providing additional context to the images.

HEIF and HEIC Support in Android

Although HEIF and HEIC were initially popularized by Apple, Android devices have also started to support these formats. Android 10 (API level 29) introduced native support for decoding HEIF images. You can use the androidx.heifwriter.HeifWriter API to write HEIC files programmatically. Here's an example in Kotlin:

1// Create a bitmap from an existing image
2val bitmap: Bitmap = ...
3
4// Create a new HEIC file
5val heifFile = File("path/to/new_file.heic")
6
7// Write the bitmap to the HEIC file
8HeifWriter.Builder(heifFile)
9 .setQuality(90)
10 .build()
11 .use { writer ->
12 writer.startWithLossyQuality(0.8f)
13 writer.addBitmap(bitmap)
14 }

By leveraging the androidx.heifdecoder.HeifDecoder class, you can easily decode HEIF files and display them in your Android app.

HEIF and HEIC Support in iOS

Given that Apple was one of the driving forces behind HEIF and HEIC, iOS has robust support for these formats. The UIImage class in Swift provides built-in support for working with HEIC images. Here's an example of decoding a HEIC image and displaying it in an iOS app:

1import UIKit
2
3// Load the HEIC image from a file
4if let heicURL = Bundle.main.url(forResource: "example", withExtension: "heic") {
5 if let data = try? Data(contentsOf: heicURL),
6 let image = UIImage(data: data) {
7 // Display the image in an image view
8 let imageView = UIImageView(image: image)
9 // ...
10 }
11}

iOS also offers APIs to write HEIC images using the UIImageWriteToSavedPhotosAlbum function or the PHAssetCreationRequest class in the Photos framework.

Wrapping Up

HEIF and its variant HEIC provide developers with more efficient and feature-rich alternatives to traditional image formats. With their superior compression techniques, support for metadata, and improved image quality, HEIF and HEIC have become popular choices for storing and sharing images on mobile devices. Whether you're developing for Android or iOS, understanding the differences and leveraging the appropriate APIs will allow you toharness the benefits of these formats in your applications.