Understanding HEIF Image Format and Its Implementation on Android
HEIF (High Efficiency Image File Format) offers superior compression, support for image sequences, depth and transparency, and is natively supported on iOS and Android P, with implementation options via ImageDecoder, BitmapFactory, or conversion to JPEG, though adoption faces compatibility and hardware licensing challenges.
What is HEIF Image
HEIF (High Efficiency Image File Format) is a new image format introduced by the MPEG group in 2013. Apple adopted it in iOS 11 to replace JPG using HEVC encoding, reducing storage and improving quality. Android P also provides native support for HEIF .
HEIF compared with JPEG offers higher compression ratio, image collection capabilities, support for dynamic images and derived images. Tests on nearly 2,000 apps show that over 90% already support viewing HEIF images.
Value of HEIF Images
Compression ratio up to 2.39× that of JPEG at the same quality, saving about 50% space and network traffic.
Supports storing multiple images (collections, bursts, etc.).
Supports dynamic images similar to GIF.
Supports depth information and transparency.
Main Image Format Comparison
Advantages
Higher compression (about twice that of JPEG at the same quality).
Can store depth and alpha channels.
Supports image collections and multi‑exposure effects.
Enables GIF‑like animation and Live Photo effects.
No maximum pixel limitation like JPEG.
Supports thumbnails and transparent pixels.
Chunked loading mechanism.
Disadvantages
Limited adoption and poor compatibility; each platform must add support, leading to a long industry chain.
Technical Implementation方案
1. Google does not provide a unified interface
Applications should check the OS version to determine HEIF support. Android O MR supports static HEIF decoding, while Android P supports both decoding and encoding.
Method 1: Use the new ImageDecoder class introduced in Android P
Reference implementation (image):
Method 2: Use the legacy BitmapFactory class
This requires minimal changes; simply enable HEIF loading on Android P devices without modifying existing image‑loading code.
Reference implementation (image):
Method 3: Convert HEIF to JPEG
When sending images to devices that do not support HEIF, convert the file to JPEG first. The conversion can be done using Google’s native APIs.
Key steps:
Decode the HEIF image with BitmapFactory to obtain an RGB bitmap.
Compress the bitmap to JPEG using Bitmap.compress() with a quality value (recommended 95).
Use the resulting JPEG for transmission.
Performance test on an Android P Pixel XL using bitmapfactory with resolution 1440×960 and quality 95 took about 200 ms; results vary across devices.
Recommended Image Scanning Approach
Method 1 (Recommended): Scan via ContentProvider
Use ContentProvider to retrieve all locally stored images, letting the system filter supported formats automatically.
Reference implementation (image):
Method 2 (Not Recommended): Self‑scan
Manually enumerate files and check extensions .heif or .heic to determine HEIF support, which adds complexity and may miss newer formats.
Outlook
Not all phones can support HEIF due to hardware and patent licensing constraints. Manufacturers need to license HEVC technology; flagship chips from Qualcomm, MediaTek, and Samsung already support it, but many mid‑range devices do not.
Experience and Recommendations
The many advantages of HEIF give it strong market potential, and Android P’s native support confirms this trend. Developers are encouraged to adapt their apps to handle HEIF images promptly.
References
Huawei technical documentation and the original article: https://blog.csdn.net/lin20044140410/article/details/88577790
Sohu Tech Products
A knowledge-sharing platform for Sohu's technology products. As a leading Chinese internet brand with media, video, search, and gaming services and over 700 million users, Sohu continuously drives tech innovation and practice. We’ll share practical insights and tech news here.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.