קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
פורמט התמונה Ultra HDR מאפשר לתמונות לאחסן יותר מידע על עוצמת האור, וכתוצאה מכך, להציג הדגשות וצללים מפורטים יותר וצבעים עזים יותר. Android תומך בתמונות Ultra HDR החל מ-Android 14 (רמת API 34). אם האפליקציה שלכם פועלת בגרסאות האלה, חשוב להגדיר אותה כך שהתמונות יוצגו בצורה תקינה. מצד שני, אם האפליקציה לא מציגה תמונות ב-Ultra HDR, אפשר לחסוך במשאבי המכשיר על ידי השבתת התצוגה ב-Ultra HDR. בדף הזה מוסבר איך לבדוק אם יש תמיכה ב-Ultra HDR בגרפיקה, ואיך להציג אותה בצורה נכונה.
בדיקה אם קיימת מפת עוצמה
תמונות Ultra HDR מכילות מפת הגברה. מפת ההגברה משמשת לקביעת הבהירות המוגברת של כל פיקסל בתמונה. כדי לבדוק אם תמונה היא בפורמט Ultra HDR, ממירים את התמונה או את רכיב ה-drawable ל-Bitmap וקוראים ל-Bitmap.hasGainMap() (זמין מ-Android 14) כדי לבדוק אם יש לה מפת גוונים.
הגדרת החלון להצגת Ultra HDR
כדי להציג תמונות באיכות Ultra HDR עם הטווח הדינמי המלא, צריך להגדיר את מצב הצבע של החלון ל-ActivityInfo.COLOR_MODE_HDR. כדי לעשות את זה, קוראים ל-method setColorMode() של החלון. (ממשקי ה-API האלה זמינים מ-Android 8, אבל התמונות לא מוצגות ב-Ultra HDR אלא אם במכשיר מותקנת גרסה Android 14 ומעלה).
סיכום של כל המידע
הקוד הבא מראה איך התהליך כולו נראה. הקוד הזה מניח שתמונה נטענת ל-Bitmap, ובודק אם לתמונה יש מפת עוצמה. אם כן, הקוד משנה את מצב הצבע של החלון ל-COLOR_MODE_HDR. אם לתמונה אין מפת גוונים, הקוד מעביר את החלון למצב הצבע שמוגדר כברירת מחדל.
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);
מקורות מידע נוספים
מידע נוסף על תמונות באיכות Ultra HDR זמין במקורות המידע הבאים:
דוגמאות התוכן והקוד שבדף הזה כפופות לרישיונות המפורטים בקטע רישיון לתוכן. Java ו-OpenJDK הם סימנים מסחריים או סימנים מסחריים רשומים של חברת Oracle ו/או של השותפים העצמאיים שלה.
עדכון אחרון: 2025-08-27 (שעון UTC).
[[["התוכן קל להבנה","easyToUnderstand","thumb-up"],["התוכן עזר לי לפתור בעיה","solvedMyProblem","thumb-up"],["סיבה אחרת","otherUp","thumb-up"]],[["חסרים לי מידע או פרטים","missingTheInformationINeed","thumb-down"],["התוכן מורכב מדי או עם יותר מדי שלבים","tooComplicatedTooManySteps","thumb-down"],["התוכן לא עדכני","outOfDate","thumb-down"],["בעיה בתרגום","translationIssue","thumb-down"],["בעיה בדוגמאות/בקוד","samplesCodeIssue","thumb-down"],["סיבה אחרת","otherDown","thumb-down"]],["עדכון אחרון: 2025-08-27 (שעון 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)"]]