From 79096c7a49c83bea9c033485334a9b0199e6b80d Mon Sep 17 00:00:00 2001 From: "ahmed.atwa" Date: Thu, 9 Mar 2023 17:05:06 +0200 Subject: [PATCH] fix camera captured file is corrupted --- README.md | 3 ++- filepicker/build.gradle | 2 +- .../java/com/atwa/filepicker/decoder/UriDecoder.kt | 14 +++++--------- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index f2dd2c7..7f52d5d 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ made in uploading them to server without the need to ask use for a single permis ``` dependencies { - implementation 'com.github.atwa:filepicker:1.0.5' + implementation 'com.github.atwa:filepicker:1.0.7' } ``` @@ -118,6 +118,7 @@ made in uploading them to server without the need to ask use for a single permis | 1.0.4 | Enhancement : Avoid possible activity reference leaking.
Feature : Implement camera image picker. | | 1.0.5 | Feature : Support fragments.
Feature : Implement file picking from initial directory.
fix : obsolete app icon unintended overriding. | | 1.0.6 | Enhancement : Add file extension to video files and images picked from camera. | +| 1.0.7 | Fix bug : Captured image file from camera is corrupted. | diff --git a/filepicker/build.gradle b/filepicker/build.gradle index a6329a8..4a2ce01 100644 --- a/filepicker/build.gradle +++ b/filepicker/build.gradle @@ -44,7 +44,7 @@ afterEvaluate { groupId = 'com.github.atwa' artifactId = 'filepicker' - version = '1.0.6' + version = '1.0.7' } } repositories { diff --git a/filepicker/src/main/java/com/atwa/filepicker/decoder/UriDecoder.kt b/filepicker/src/main/java/com/atwa/filepicker/decoder/UriDecoder.kt index bd10a6d..5310650 100644 --- a/filepicker/src/main/java/com/atwa/filepicker/decoder/UriDecoder.kt +++ b/filepicker/src/main/java/com/atwa/filepicker/decoder/UriDecoder.kt @@ -62,26 +62,22 @@ internal class UriDecoder( } private fun saveImageToFile(bitmap: Bitmap): ImageMeta? { - var byteStream: ByteArrayInputStream? = null + var outputStream: FileOutputStream? = null return try { val fileName = TimeUnit.MILLISECONDS.toSeconds(System.currentTimeMillis()).toString().plus(".jpg") val imageFile = File(context?.cacheDir, fileName) - val size = imageFile.length().getFileSize() - val byteArray = (bitmap.allocationByteCount * bitmap.height).run { - ByteBuffer.allocate(this) - }.apply { bitmap.copyPixelsToBuffer(this) }.array() - byteStream = ByteArrayInputStream(byteArray) - val outputStream = FileOutputStream(imageFile) + outputStream = FileOutputStream(imageFile) + bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream) - streamer.copyFile(byteStream, outputStream) + val size = imageFile.length().getFileSize() ImageMeta(fileName, size, imageFile, bitmap) } catch (e: Exception) { println(e.message) null } finally { - byteStream?.close() + outputStream?.close() } }