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);
[null,null,["最終更新日 2025-08-21 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)"]]