-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from Atwa/enhancemnt/add_file_extensions
return high quality camera captured image
- Loading branch information
Showing
9 changed files
with
255 additions
and
79 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
filepicker/src/main/java/com/atwa/filepicker/decoder/BitmapRotation.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package com.atwa.filepicker.decoder | ||
|
||
import android.content.ContentResolver | ||
import android.graphics.Bitmap | ||
import android.graphics.Matrix | ||
import android.media.ExifInterface | ||
import android.net.Uri | ||
import android.os.Build | ||
import java.io.IOException | ||
import java.io.InputStream | ||
|
||
class BitmapRotation(private val contentResolver: ContentResolver?, val uri: Uri) { | ||
|
||
private fun getRotationAngle(): Float { | ||
return try { | ||
val exifInterface = getExifInterface() ?: return 0f | ||
val orientation = exifInterface.getAttributeInt( | ||
ExifInterface.TAG_ORIENTATION, | ||
ExifInterface.ORIENTATION_UNDEFINED | ||
) | ||
when (orientation) { | ||
ExifInterface.ORIENTATION_ROTATE_90 -> 90f | ||
ExifInterface.ORIENTATION_ROTATE_180 -> 180f | ||
ExifInterface.ORIENTATION_ROTATE_270 -> 270f | ||
ExifInterface.ORIENTATION_NORMAL -> 0f | ||
ExifInterface.ORIENTATION_UNDEFINED -> -1f | ||
else -> -1f | ||
} | ||
} catch (e: java.lang.Exception) { | ||
e.printStackTrace() | ||
0f | ||
} | ||
} | ||
|
||
private fun getExifInterface(): ExifInterface? { | ||
var inputStream: InputStream? = null | ||
try { | ||
val path = uri.toString() | ||
if (path.startsWith("file://")) { | ||
return ExifInterface(path) | ||
} | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { | ||
if (path.startsWith("content://")) { | ||
inputStream = contentResolver?.openInputStream(uri) | ||
return inputStream?.let { ExifInterface(it) } | ||
} | ||
} | ||
} catch (e: IOException) { | ||
e.printStackTrace() | ||
} finally { | ||
inputStream?.close() | ||
} | ||
return null | ||
} | ||
|
||
fun rotateAccordingToOrientation(bitmap: Bitmap?): Bitmap? { | ||
return bitmap?.let { | ||
val matrix = Matrix() | ||
matrix.postRotate(getRotationAngle()) | ||
val scaledBitmap = Bitmap.createScaledBitmap(bitmap, bitmap.width, bitmap.height, true) | ||
Bitmap.createBitmap( | ||
scaledBitmap, | ||
0, | ||
0, | ||
scaledBitmap.width, | ||
scaledBitmap.height, | ||
matrix, | ||
true | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.