0.4.2 - Fixed issue with photo upload streams
This commit is contained in:
@@ -14,8 +14,8 @@ android {
|
|||||||
applicationId = "com.atridad.openclimb"
|
applicationId = "com.atridad.openclimb"
|
||||||
minSdk = 31
|
minSdk = 31
|
||||||
targetSdk = 35
|
targetSdk = 35
|
||||||
versionCode = 8
|
versionCode = 9
|
||||||
versionName = "0.4.1"
|
versionName = "0.4.2"
|
||||||
|
|
||||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,40 +35,32 @@ object ImageUtils {
|
|||||||
*/
|
*/
|
||||||
fun saveImageFromUri(context: Context, imageUri: Uri): String? {
|
fun saveImageFromUri(context: Context, imageUri: Uri): String? {
|
||||||
return try {
|
return try {
|
||||||
val inputStream = context.contentResolver.openInputStream(imageUri)
|
// Decode bitmap from a fresh stream to avoid mark/reset dependency
|
||||||
inputStream?.use { input ->
|
val originalBitmap = context.contentResolver.openInputStream(imageUri)?.use { input ->
|
||||||
// Decode with options to get EXIF data
|
BitmapFactory.decodeStream(input)
|
||||||
val options = BitmapFactory.Options().apply {
|
} ?: return null
|
||||||
inJustDecodeBounds = true
|
|
||||||
}
|
|
||||||
input.reset()
|
|
||||||
BitmapFactory.decodeStream(input, null, options)
|
|
||||||
|
|
||||||
// Reset stream and decode with proper orientation
|
val orientedBitmap = correctImageOrientation(context, imageUri, originalBitmap)
|
||||||
input.reset()
|
val compressedBitmap = compressImage(orientedBitmap)
|
||||||
val originalBitmap = BitmapFactory.decodeStream(input)
|
|
||||||
val orientedBitmap = correctImageOrientation(context, imageUri, originalBitmap)
|
|
||||||
val compressedBitmap = compressImage(orientedBitmap)
|
|
||||||
|
|
||||||
// Generate unique filename
|
// Generate unique filename
|
||||||
val filename = "${UUID.randomUUID()}.jpg"
|
val filename = "${UUID.randomUUID()}.jpg"
|
||||||
val imageFile = File(getImagesDirectory(context), filename)
|
val imageFile = File(getImagesDirectory(context), filename)
|
||||||
|
|
||||||
// Save compressed image
|
// Save compressed image
|
||||||
FileOutputStream(imageFile).use { output ->
|
FileOutputStream(imageFile).use { output ->
|
||||||
compressedBitmap.compress(Bitmap.CompressFormat.JPEG, IMAGE_QUALITY, output)
|
compressedBitmap.compress(Bitmap.CompressFormat.JPEG, IMAGE_QUALITY, output)
|
||||||
}
|
|
||||||
|
|
||||||
// Clean up bitmaps
|
|
||||||
originalBitmap.recycle()
|
|
||||||
if (orientedBitmap != originalBitmap) {
|
|
||||||
orientedBitmap.recycle()
|
|
||||||
}
|
|
||||||
compressedBitmap.recycle()
|
|
||||||
|
|
||||||
// Return relative path
|
|
||||||
"$IMAGES_DIR/$filename"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Clean up bitmaps
|
||||||
|
originalBitmap.recycle()
|
||||||
|
if (orientedBitmap != originalBitmap) {
|
||||||
|
orientedBitmap.recycle()
|
||||||
|
}
|
||||||
|
compressedBitmap.recycle()
|
||||||
|
|
||||||
|
// Return relative path
|
||||||
|
"$IMAGES_DIR/$filename"
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
null
|
null
|
||||||
|
|||||||
Reference in New Issue
Block a user