[null,null,["最后更新时间 (UTC):2025-08-21。"],[],[],null,["# Edit Ultra HDR images\n\nThe [Ultra HDR image format](/guide/topics/media/platform/hdr-image-format) encodes luminosity information\nthat lets devices display brighter\nimages with more intense colors. When your app edits an Ultra HDR image, you\nwant to make sure to preserve that luminosity information. This is important even if the\nuser's device doesn't support displaying an Ultra HDR image at full\nintensity. After all, the user might share their image to someone with a device\nthat supports Ultra HDR, or they might save that image and look at it again on a\nnew device years later.\n\nThe good news is most Android methods for editing bitmaps support the Ultra HDR\nimage format. If you're making basic edits to an image, like cropping or\nrotating it, the standard Android methods do the job---you'll end up with an\nultra HDR image with the new dimensions or orientation.\n\nThe job is trickier if you're modifying the contents of the image. In those\ncases, the standard editing methods preserve the luminosity information of the\n*old* image, which might not be what you want. In those cases, you might need to\nedit or remove the gain map (which encodes the image's luminosity information)\nto get the right result.\n\n### Ultra HDR format overview\n\nThe Ultra HDR image format is described in detail in the [Ultra HDR Image\nspecification](/guide/topics/media/platform/hdr-image-format). The most important thing to understand is an\nUltra HDR image contains both a *primary image* and a *gain map*.\n\n- The *primary image* has the color information for each pixel of the image.\n- The *gain map* is a standard JPEG image with the same proportions as the primary image, though not necessarily the same pixel dimensions. Each pixel of the gain map specifies the luminance of the corresponding part of the primary image.\n\nThe gain map can be either grayscale or color. If the gain map is in color, each\ncolor channel on the gain map specifies the luminance of that color channel on\nthe corresponding part of the primary image. If the gain map is grayscale, each\npixel of the gain map specifies the luminance of all three color channels on\nthat portion of the primary image.\n\nThe gain map must have the same proportions as the primary image, but it does\nnot have to have the same pixel dimensions. In fact, when the Android platform\ncreates Ultra HDR images, it creates a gain map with a smaller width and height\nthan the primary image; doing so makes the file size significantly smaller, but\nstill encodes enough information for a good result. This means that each pixel\nin the gain map might store the luminance information for several pixels in the\nprimary image.\n\n### Basic Ultra HDR edits\n\nIf you use the Android [`Bitmap`](/reference/android/graphics/Bitmap) APIs to make\nbasic transformations to an Ultra HDR image, the methods make the appropriate\nchanges to the gain map. The following `Bitmap` operations are supported:\n\n- **Rotate:** If you rotate an Ultra HDR image, the method rotates the gain map too.\n- **Crop:** If you crop an Ultra HDR image, the method crops the gain map appropriately.\n- **Scale:** If you scale an Ultra HDR image, the method scales the gain map so it has half the width and half the height of the resized primary image.\n\nIn each case, the luminosity information is preserved.\n\n### Advanced Ultra HDR edits\n\nIf you make more elaborate edits to an Ultra HDR image, the gain map is\npreserved unchanged, which may not give you the results you want.\n\nCommon edits that might result in this situation include:\n\n- **Adding stickers or emoji:** The added sticker would have the same luminosity and color vividness values as the area it was pasted on.\n- **Overlaying a second image:** The new image would use the luminosity and color vividness information of the content it's overlaying.\n- **Adding filters:** The old gain map's information might not be appropriate for the modified primary image.\n\nIn each case, the old luminosity and color vividness information is preserved,\nbut it might not be appropriate for the modified image.\n\nIf the original gain map is appropriate for the edited image, you don't have to\ndo anything. If you *do* want to modify the gain map, the usual workflow is:\n\n1. **Fetch the image's current gain map** by calling [`Bitmap.getGainmap()`](/reference/android/graphics/Bitmap#getGainmap()) and cache it.\n2. **Modify the primary image as desired.**\n3. **Make corresponding edits to the cached gain map.** For example, if you\n pasted an emoji onto the primary image, you might set the corresponding\n portion of the gain map to a neutral value, like [`Color.GRAY`](/reference/android/graphics/Color#GRAY).\n\n | **Important:** The gain map might not have the same pixel dimensions as the primary image. For this reason, you need to calculate the appropriate pixels on the gain map that correspond to the edited areas on the primary image. For example, suppose the primary image is 8,000×4,000 pixels, and the gain map is 2,000×1,000 pixels. If you edit pixel (500,600) on the primary image, the corresponding pixel on the gain map would be at location (125,150).\n4. **Apply the modified gain map back to the image** by calling\n [`Bitmap.setGainmap()`](/reference/android/graphics/Bitmap#setGainmap(android.graphics.Gainmap))).\n\n### Additional resources\n\nTo learn more about Ultra HDR images, see the following additional resources:\n\n- [Ultra HDR image format specification](/guide/topics/media/platform/hdr-image-format)"]]