ARCore 可讓您使用 ImageMetadata
從相機圖片擷取結果中存取中繼資料鍵值。您可能會想存取的常見相機圖片中繼資料類型包括焦距、圖片時間戳記資料或光源資訊。
Android Camera
模組可以為每個擷取的影格記錄 160 個以上的圖片參數 (視裝置功能而定)。如需所有可能的中繼資料鍵清單,請參閱 ImageMetadata
。
取得個別中繼資料鍵的值
使用 getImageMetadata()
取得特定中繼資料鍵值,並在 MetadataNotFoundException
無法使用時擷取。以下範例說明如何取得 SENSOR_EXPOSURE_TIME
中繼資料鍵值。
Java
// Obtain the SENSOR_EXPOSURE_TIME metadata value from the frame. Long getSensorExposureTime(Frame frame) { try { // Can throw NotYetAvailableException when sensors data is not yet available. ImageMetadata metadata = frame.getImageMetadata(); // Get the exposure time metadata. Throws MetadataNotFoundException if it's not available. return metadata.getLong(ImageMetadata.SENSOR_EXPOSURE_TIME); } catch (MetadataNotFoundException | NotYetAvailableException exception) { return null; } }
Kotlin
// Obtain the SENSOR_EXPOSURE_TIME metadata value from the frame. fun getSensorExposureTime(frame: Frame): Long? { return runCatching { // Can throw NotYetAvailableException when sensors data is not yet available. val metadata = frame.imageMetadata // Get the exposure time metadata. Throws MetadataNotFoundException if it's not available. return metadata.getLong(ImageMetadata.SENSOR_EXPOSURE_TIME) } .getOrNull() }