Stay organized with collections
Save and categorize content based on your preferences.
The Ultra HDR image format lets images store more information
about the intensity of light, resulting in more detailed highlights and shadows,
and more intense colors. Android provides support for Ultra HDR images beginning
with Android 14 (API level 34). If your app is running on those versions, it's
important to configure your app to display these images properly. On the other
hand, if your app isn't displaying Ultra HDR images, you can save device
resources by not enabling Ultra HDR display. This page explains how to check
whether graphics support Ultra HDR, and how to display them properly.
Check for the presence of a gain map
Ultra HDR images contain a gain map. The gain map is
used to determine the increased brightness of each pixel in the image. To verify
if an image is in the Ultra HDR format, convert the image or drawable into a
Bitmap and call Bitmap.hasGainMap()
(available since Android 14) to check if it has a gain map.
Configure your window to display Ultra HDR
To display Ultra HDR images with the full dynamic range, set the window's color
mode to ActivityInfo.COLOR_MODE_HDR. Do this by calling the
window's setColorMode() method. (These APIs are
available from Android 8; however, images are not displayed in Ultra HDR unless
the device is running Android 14 or higher.)
Putting it all together
The following code shows how the whole process looks. This code assumes an image
is loaded into a Bitmap, and checks if the image has a gain map. If it does, the
code switches the window's color mode to COLOR_MODE_HDR. If
the image does not have a gain map, the code switches the window to the default
color mode.
Kotlin
valbitmap=/* Get Bitmap from Image Resource */binding.imageContainer.setImageBitmap(bitmap)// Set color mode of the activity to the correct color mode.requireActivity().window.colorMode=if(bitmap.hasGainmap())ActivityInfo.COLOR_MODE_HDRelseActivityInfo.COLOR_MODE_DEFAULT
Java
finalBitmapbitmap=/* Get Bitmap from Image Resource */binding.imageContainer.setImageBitmap(bitmap);// Set color mode of the activity to the correct color mode.intcolorMode=ActivityInfo.COLOR_MODE_DEFAULT;if(bitmap.hasGainmap())colorMode=ActivityInfo.COLOR_MODE_HDR;requireActivity().getWindow().setColorMode(colorMode);
Additional resources
To learn more about Ultra HDR images, see the following additional resources:
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-08-20 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-20 UTC."],[],[],null,["# Display Ultra HDR images\n\nThe [Ultra HDR image format](/guide/topics/media/platform/hdr-image-format) lets images store more information\nabout the intensity of light, resulting in more detailed highlights and shadows,\nand more intense colors. Android provides support for Ultra HDR images beginning\nwith Android 14 (API level 34). If your app is running on those versions, it's\nimportant to configure your app to display these images properly. On the other\nhand, if your app isn't displaying Ultra HDR images, you can save device\nresources by not enabling Ultra HDR display. This page explains how to check\nwhether graphics support Ultra HDR, and how to display them properly.\n\nCheck for the presence of a gain map\n------------------------------------\n\nUltra HDR images contain a [*gain map*](/guide/topics/media/platform/hdr-image-format#gain_map-generation). The gain map is\nused to determine the increased brightness of each pixel in the image. To verify\nif an image is in the Ultra HDR format, convert the image or drawable into a\n[`Bitmap`](/reference/android/graphics/Bitmap) and call [`Bitmap.hasGainMap()`](/reference/android/graphics/Bitmap#hasGainmap())\n(available since Android 14) to check if it has a gain map.\n\nConfigure your window to display Ultra HDR\n------------------------------------------\n\nTo display Ultra HDR images with the full dynamic range, set the window's color\nmode to [`ActivityInfo.COLOR_MODE_HDR`](/reference/android/content/pm/ActivityInfo#COLOR_MODE_HDR). Do this by calling the\nwindow's [`setColorMode()`](/reference/android/view/Window#setColorMode(int)) method. (These APIs are\navailable from Android 8; however, images are not displayed in Ultra HDR unless\nthe device is running Android 14 or higher.)\n| **Note:** You can set a window's color mode in the Android manifest, but we don't recommend doing this. For optimum device performance, you should dynamically change a window's color mode to HDR when you're displaying an Ultra HDR image.\n| **Note:** Android takes screenshots in SDR. HDR content is tonemapped to SDR in screenshots.\n\nPutting it all together\n-----------------------\n\nThe following code shows how the whole process looks. This code assumes an image\nis loaded into a Bitmap, and checks if the image has a gain map. If it does, the\ncode switches the window's color mode to [`COLOR_MODE_HDR`](/reference/android/content/pm/ActivityInfo#COLOR_MODE_HDR). If\nthe image does not have a gain map, the code switches the window to the default\ncolor mode. \n\n### Kotlin\n\n```kotlin\nval bitmap = /* Get Bitmap from Image Resource */\nbinding.imageContainer.setImageBitmap(bitmap)\n\n// Set color mode of the activity to the correct color mode.\nrequireActivity().window.colorMode =\n if (bitmap.hasGainmap()) ActivityInfo.COLOR_MODE_HDR else ActivityInfo.COLOR_MODE_DEFAULT\n```\n\n### Java\n\n```java\nfinal Bitmap bitmap = /* Get Bitmap from Image Resource */\nbinding.imageContainer.setImageBitmap(bitmap);\n\n// Set color mode of the activity to the correct color mode.\nint colorMode = ActivityInfo.COLOR_MODE_DEFAULT;\nif (bitmap.hasGainmap()) colorMode = ActivityInfo.COLOR_MODE_HDR;\nrequireActivity().getWindow().setColorMode(colorMode);\n```\n\nAdditional resources\n--------------------\n\nTo learn more about Ultra HDR images, see the following additional resources:\n\n- Video: [Creating high-quality Android media\n experiences](https://www.youtube.com/watch?v=sv9ICtooWBc&t=284s)\n- Sample app: [Displaying Ultra HDR](https://github.com/android/platform-samples/blob/main/samples/graphics/ultrahdr/src/main/java/com/example/platform/graphics/ultrahdr/display/DisplayingUltraHDR.kt)\n- [Ultra HDR image format specification](/guide/topics/media/platform/hdr-image-format)\n- Video: [Android Developer Story: Instagram's early adoption of Ultra HDR transforms UX in only 3 months](https://www.youtube.com/watch?v=gGFHVi3NPWM)"]]