如果需要,我可以使用以下方法旋转图像 这是Uri类的扩展方法
suspend fun Uri.rotateImageIfRequired(ctx: Context): Uri {
Log.i("AMIRA3333" , "uri2 : " + this)
val originalBitmap = MediaStore.Images.Media.getBitmap(ctx.contentResolver, this)
val originalImagePath = this.getPath(ctx)
val exifInterface = ExifInterface(originalImagePath)
val orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL)
return when (orientation) {
ExifInterface.ORIENTATION_ROTATE_90 -> TransformationUtils.rotateImage(originalBitmap, 90)
ExifInterface.ORIENTATION_ROTATE_180 -> TransformationUtils.rotateImage(originalBitmap, 180)
ExifInterface.ORIENTATION_ROTATE_270 -> TransformationUtils.rotateImage(originalBitmap, 270)
else -> originalBitmap
}.let {
GlobalScope.async {
File(originalImagePath).deleteOnExit()
Uri.parse(
MediaStore.Images.Media.insertImage(
ctx.contentResolver,
it,
System.currentTimeMillis().toString(),
null
)
)
}.await()
}
}
这是我的uri的示例:file:///storage/emulated/0/DCIM/IMG_20190219_072926.jpg
它总是返回null
有人可以建议