简体   繁体   中英

How to get the real picture size in mm using Android with arcore

I want to use the arcore in android to convert the width and height in pixels of a picture to millimeters, how can I do it?

Try this,

fun getImageWidthAndHeight(context: Context, uri: Uri): Pair<Float, Float> {
    val exif = try {
        context.contentResolver.openInputStream(uri)?.let {
            ExifInterface(it)
        } ?: return 0f to 0f
    } catch (e: FileNotFoundException) {
        return 0f to 0f
    }

    val width = exif.getAttributeInt(ExifInterface.TAG_IMAGE_WIDTH, 0).toFloat()
    val height = exif.getAttributeInt(ExifInterface.TAG_IMAGE_LENGTH, 0).toFloat()

    return when (
        exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL)
    ) {
        ExifInterface.ORIENTATION_ROTATE_90, ExifInterface.ORIENTATION_ROTATE_270 -> height to width
            else -> width to height
    }
}
...
val (width, height) = getImageWidthAndHeight(context, uri)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM