can i get image file width and height from uri in android?

前端 未结 10 2123
深忆病人
深忆病人 2020-12-08 01:58

i can getting the image width through MediaStore.Images.Media normally

but i need to getting the image width and height from image which selected from d

10条回答
  •  猫巷女王i
    2020-12-08 02:43

    Blackbelt's answer will work most of the time using Options, but I would like to propose another solution or fallback solution by using the ExifInterface. If you have the image URI, you can create the ExifInterface using the full path, no need for Bitmap object nor BitmapFactory.Options.

    ex.

    int width = exif.getAttributeInt( ExifInterface.TAG_IMAGE_WIDTH, defaultValue );
    int height = exif.getAttributeInt( ExifInterface.TAG_IMAGE_LENGTH, defaultValue ); 
    

提交回复
热议问题