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() }