ข้อมูลเมตาของรูปภาพกล้อง

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