自 2025 年 3 月 27 日起,我们建议您使用 android-latest-release
而非 aosp-main
构建 AOSP 并为其做出贡献。如需了解详情,请参阅 AOSP 的变更。
HEIF 图片处理
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
搭载 Android 10 的设备支持 HEIC 压缩图片格式,它是 ISO/IEC 23008-12 中规定的高效图片文件格式 (HEIF) 的高效视频编码 (HEVC) 特定品牌。与 JPEG 文件相比,HEIC 编码的图片质量更好且文件更小。
HEIC 图片由相机框架生成,请求来自相机 HAL 的未压缩图片并将其发送到媒体子系统,以便由 HEIC 或 HEVC 编码器进行编码。
要求
如需支持 HEIC 图片格式,您的设备必须拥有支持 MIMETYPE_IMAGE_ANDROID_HEIC
或 MIMETYPE_VIDEO_HEVC
(具有恒定质量模式)的硬件编码器。
实现
如需在您的设备上支持 HEIC 图片格式,请实现 HEIC/HEVC 编解码器,并为所需的流配置(即 IMPLEMENTATION_DEFINED
/YUV
流和 JPEG 应用细分流)提供支持。
对于相应的硬件,以恒定质量 (CQ) 模式实现 HEIC/HEVC 编解码器,如下所示:
- HEVC 类型编解码器使用具有
GRALLOC_USAGE_HW_VIDEO_ENCODER
用法的 IMPLEMENTATION_DEFINED
格式或 HAL_PIXEL_FORMAT_YCBCR_420_888
格式,具体取决于图片大小。
- HEIC 类型编解码器使用具有
GRALLOC_USAGE_HW_IMAGE_ENCODER
用法的 IMPLEMENTATION_DEFINED
格式。
相机
在静态元数据中,将 ANDROID_HEIC_INFO_SUPPORTED
设置为 true,并将 ANDROID_HEIC_INFO_MAX_JPEG_APP_SEGMENTS_COUNT
设置为介于 [1, 16]
之间的值,以表明 JPEG 应用细分的数量。
对于每个必要的流组合,您的摄像头设备必须支持使用相同大小的 HEIC 流替换 JPEG 流。
对于公共 API 上的 HEIC 输出流,摄像头服务会创建两个 HAL 内部流:
- 具有
JPEG_APPS_SEGMENT
使用标志的 BLOB 流,可存储应用细分(包括 EXIF 和缩略图细分)
IMPLEMENTATION_DEFINED
和 YCBCR_420_888
会根据目标编解码器和 HEIC 流的大小流式传输 HEIC 流的大小
相机框架根据 ANDROID_HEIC_INFO_MAX_JPEG_APP_SEGMENTS_COUNT
为相机 HAL 分配足够大的缓冲区,以便填充 JPEG 应用细分。APP1
细分为必填项,但 APP1
之后(APP2
及以上)的细分为可选项。相机框架可以覆盖 APP1
细分中的 EXIF 标记(这些标记可以派生自捕获结果元数据或者与主图片比特流相关),并将它们发送至 MediaMuxer
。
由于媒体编码器将屏幕方向嵌入到输出图片的元数据中,以确保主图片和缩略图的屏幕方向一致,因此相机 HAL 不得根据 android.jpeg.orientation.
旋转缩略图。该框架将屏幕方向写入到 EXIF 元数据和 HEIC 容器中。
与 JPEG 格式相关的静态、控制和动态元数据标记也适用于 HEIC 格式。例如,捕获请求中的 android.jpeg.orientation
和 android.jpeg.quality
元数据标记用于控制 HEIC 图片的屏幕方向和质量。
如需在应用中使用 HEIC 格式,请使用 HEIC 公共 API。
如需了解详情,请参阅以下来源。
相机 HAL
图形缓冲区数据空间
图形缓冲区使用空间
验证
如需验证您的实现是否支持 HEIC 图片,请使用 TestingCamera2
测试应用,并运行以下摄像头 CTS 和 VTS 测试。
摄像头 CTS 测试
摄像头 VTS 测试
本页面上的内容和代码示例受内容许可部分所述许可的限制。Java 和 OpenJDK 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-03-26。
[[["易于理解","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"]],["最后更新时间 (UTC):2025-03-26。"],[],[],null,["# HEIF imaging\n\nDevices running Android 10 support the HEIC\ncompressed image format, a high\nefficiency video encoding (HEVC) specific *brand* of the high efficiency image\nfile format (HEIF) as specified in\n[ISO/IEC 23008-12](https://www.iso.org/standard/66067.html).\nHEIC-encoded images offer\nbetter image quality with smaller file sizes as compared to JPEG files.\n\nHEIC images are generated by the camera framework requesting an uncompressed\nimage from the\n[camera HAL](/docs/core/camera/camera3) and sending it to the media subsystem to\nbe encoded by an HEIC or HEVC encoder.\n\nRequirements\n------------\n\nTo support the HEIC image format, your device must have a hardware encoder\nsupporting\n[`MIMETYPE_IMAGE_ANDROID_HEIC`](https://developer.android.com/reference/android/media/MediaFormat.html#MIMETYPE_IMAGE_ANDROID_HEIC)\nor\n[`MIMETYPE_VIDEO_HEVC`](https://developer.android.com/reference/android/media/MediaFormat.html#MIMETYPE_VIDEO_HEVC)\nwith the\n[constant quality mode](https://developer.android.com/reference/android/media/MediaCodecInfo.EncoderCapabilities.html#BITRATE_MODE_CQ).\n\nImplementation\n--------------\n\nTo support the HEIC image format on your device, implement an HEIC/HEVC codec\nand provide support for the required stream configurations, which are the\n`IMPLEMENTATION_DEFINED`/`YUV` streams and JPEG app segment streams.\n\n### Media\n\nImplement the HEIC/HEVC codec in constant quality (CQ) mode for the\ncorresponding hardware as follows:\n\n- The HEVC type codec consumes either the `IMPLEMENTATION_DEFINED` format with the `GRALLOC_USAGE_HW_VIDEO_ENCODER` usage or the `HAL_PIXEL_FORMAT_YCBCR_420_888` format depending on the image size.\n- The HEIC type codec consumes the `IMPLEMENTATION_DEFINED` format with the `GRALLOC_USAGE_HW_IMAGE_ENCODER` usage.\n\n### Camera\n\nIn the static metadata, set `ANDROID_HEIC_INFO_SUPPORTED` to true, and\n`ANDROID_HEIC_INFO_MAX_JPEG_APP_SEGMENTS_COUNT` to a value between `[1, 16]`,\nindicating the number of JPEG app segments.\n\nFor each mandatory stream combination, your camera device must support swapping\na JPEG stream with a HEIC stream of the same size.\n\nFor an HEIC output stream at the public API, the camera service creates two HAL\ninternal streams:\n\n- A BLOB stream with the `JPEG_APPS_SEGMENT` usage flag to store app segments including EXIF and thumbnail segments\n- An `IMPLEMENTATION_DEFINED` or `YCBCR_420_888` stream the size of the HEIC stream depending on the target codec and HEIC stream size\n\nBased on `ANDROID_HEIC_INFO_MAX_JPEG_APP_SEGMENTS_COUNT`, the camera framework\nallocates buffers large enough for the camera HAL to populate the JPEG app\nsegments. The `APP1` segment is required but segments following the `APP1`\nsegment (`APP2` and above) are optional. The camera framework overrides the EXIF\ntags in the `APP1` segment that can be derived from the capture result metadata\nor are related to the main image bitstream and sends them to `MediaMuxer`.\n\nBecause the media encoder embeds the orientation in the metadata of output\nimages, to ensure a consistent orientation between the main image and thumbnail,\nthe camera HAL must not rotate the thumbnail image based on\n`android.jpeg.orientation.` The framework writes the orientation into the EXIF\nmetadata and HEIC container.\n\nThe static, control, and dynamic metadata tags related to the JPEG format also\napply to the HEIC format. For example, the `android.jpeg.orientation` and\n`android.jpeg.quality` metadata tags in the capture request are used to control\nthe orientation and quality of HEIC images.\n| **Note:** JPEG and HEIC streams can't be configured at the same time.\n\nTo use the HEIC format in an app, use the\n[HEIC public API](https://developer.android.com/reference/android/graphics/ImageFormat#HEIC).\n\nFor more information, see the following sources.\n\n**Camera HAL**\n\n- [`docs.html`](https://android.googlesource.com/platform/system/media/+/a44fd450eae51e671b1020d4f2fb146b181bc1f7/camera/docs/docs.html#31733)\n- [`CameraBlob`](https://android.googlesource.com/platform/hardware/interfaces/+/55386823a318309bfe1cc40175afa615225cabb1/camera/device/3.5/types.hal#156)\n- [`ANDROID_HEIC_INFO_SUPPORTED`](https://android.googlesource.com/platform/hardware/interfaces/+/55386823a318309bfe1cc40175afa615225cabb1/camera/metadata/3.4/types.hal#166)\n- [`ANDROID_HEIC_INFO_MAX_JPEG_APP_SEGMENTS_COUNT`](https://android.googlesource.com/platform/hardware/interfaces/+/55386823a318309bfe1cc40175afa615225cabb1/camera/metadata/3.4/types.hal#172)\n\n**Graphic buffer data space**\n\n- [`JPEG_APP_SEGMENTS`](https://android.googlesource.com/platform/hardware/interfaces/+/55386823a318309bfe1cc40175afa615225cabb1/graphics/common/1.2/types.hal#66)\n- [`HEIF`](https://android.googlesource.com/platform/hardware/interfaces/+/55386823a318309bfe1cc40175afa615225cabb1/graphics/common/1.2/types.hal#77)\n\n**Graphic buffer usage space**\n\n- [`HW_IMAGE_ENCODER`](https://android.googlesource.com/platform/hardware/interfaces/+/55386823a318309bfe1cc40175afa615225cabb1/graphics/common/1.2/types.hal#105)\n\nValidation\n----------\n\nTo validate that your implementation supports HEIC images, use the\n[`TestingCamera2`](https://android.googlesource.com/platform/pdk/+/refs/heads/android16-release/apps/TestingCamera2/)\ntest app and run the following camera CTS and VTS tests.\n\n**Camera CTS tests**\n\n- [`NativeImageReaderTest#testHeic`](https://android.googlesource.com/platform/cts/+/refs/heads/android16-release/tests/camera/src/android/hardware/camera2/cts/NativeImageReaderTest.java#46)\n- [`ImageReaderTest#testHeic`](https://android.googlesource.com/platform/cts/+/refs/heads/android16-release/tests/camera/src/android/hardware/camera2/cts/ImageReaderTest.java#207)\n- [`ImageReaderTest#testRepeatingHeic`](https://android.googlesource.com/platform/cts/+/refs/heads/android16-release/tests/camera/src/android/hardware/camera2/cts/ImageReaderTest.java#257)\n- [`ReprocessCaptureTest#testBasicYuvToHeicReprocessing`](https://android.googlesource.com/platform/cts/+/refs/heads/android16-release/tests/camera/src/android/hardware/camera2/cts/ReprocessCaptureTest.java#122)\n- [`ReprocessCaptureTest#testBasicOpaqueToHeicReprocessing`](https://android.googlesource.com/platform/cts/+/refs/heads/android16-release/tests/camera/src/android/hardware/camera2/cts/ReprocessCaptureTest.java#170)\n- [`RobustnessTest#testMandatoryOutputCombinations`](https://android.googlesource.com/platform/cts/+/refs/heads/android16-release/tests/camera/src/android/hardware/camera2/cts/RobustnessTest.java#230)\n- [`StillCaptureTest#testHeicExif`](https://android.googlesource.com/platform/cts/+/refs/heads/android16-release/tests/camera/src/android/hardware/camera2/cts/StillCaptureTest.java#116)\n\n**Camera VTS tests**\n\n- [`VtsHalCameraProviderV2_4TargetTest.cpp`](https://android.googlesource.com/platform/hardware/interfaces/+/refs/heads/android16-release/camera/provider/2.4/vts/functional/VtsHalCameraProviderV2_4TargetTest.cpp#2357)"]]