با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
فرمت تصویر Ultra HDR به تصاویر اجازه میدهد اطلاعات بیشتری در مورد شدت نور ذخیره کنند و در نتیجه نقاط برجستهتر و سایههای دقیقتر و رنگهای تندتری به دست میآیند. Android از تصاویر Ultra HDR که با Android 14 شروع می شود (سطح API 34) پشتیبانی می کند. اگر برنامه شما روی آن نسخه ها اجرا می شود، مهم است که برنامه خود را برای نمایش درست این تصاویر پیکربندی کنید. از طرف دیگر، اگر برنامه شما تصاویر Ultra HDR را نمایش نمی دهد، می توانید با فعال نکردن نمایش Ultra HDR در منابع دستگاه ذخیره کنید. این صفحه نحوه بررسی اینکه آیا گرافیک ها از Ultra HDR پشتیبانی می کنند و نحوه نمایش صحیح آنها را توضیح می دهد.
وجود نقشه افزایش را بررسی کنید
تصاویر Ultra HDR حاوی یک نقشه افزایش هستند. نقشه افزایش برای تعیین روشنایی افزایش یافته هر پیکسل در تصویر استفاده می شود. برای بررسی اینکه آیا یک تصویر در فرمت Ultra HDR است، تصویر یا قابل ترسیم را به Bitmap تبدیل کنید و با Bitmap.hasGainMap() (از اندروید 14 موجود است) تماس بگیرید تا بررسی کنید که آیا نقشه بهره دارد یا خیر.
پنجره خود را برای نمایش Ultra HDR پیکربندی کنید
برای نمایش تصاویر Ultra HDR با محدوده دینامیکی کامل، حالت رنگ پنجره را روی ActivityInfo.COLOR_MODE_HDR تنظیم کنید. این کار را با فراخوانی متد setColorMode() پنجره انجام دهید. (این APIها از اندروید 8 در دسترس هستند؛ با این حال، تصاویر در Ultra HDR نمایش داده نمی شوند مگر اینکه دستگاه دارای اندروید 14 یا بالاتر باشد.)
همه را کنار هم گذاشتن
کد زیر نشان می دهد که کل فرآیند چگونه به نظر می رسد. این کد فرض میکند که یک تصویر در Bitmap بارگذاری شده است و بررسی میکند که آیا تصویر دارای نقشه بهره است یا خیر. در این صورت، کد حالت رنگ پنجره را به COLOR_MODE_HDR تغییر میدهد. اگر تصویر نقشه بهره نداشته باشد، کد پنجره را به حالت رنگ پیشفرض تغییر میدهد.
کاتلین
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
جاوا
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);
منابع اضافی
برای کسب اطلاعات بیشتر در مورد تصاویر Ultra HDR، به منابع اضافی زیر مراجعه کنید:
محتوا و نمونه کدها در این صفحه مشمول پروانههای توصیفشده در پروانه محتوا هستند. جاوا و OpenJDK علامتهای تجاری یا علامتهای تجاری ثبتشده Oracle و/یا وابستههای آن هستند.
تاریخ آخرین بهروزرسانی 2025-08-27 بهوقت ساعت هماهنگ جهانی.
[null,null,["تاریخ آخرین بهروزرسانی 2025-08-27 بهوقت ساعت هماهنگ جهانی."],[],[],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)"]]