Skip to content

Commit

Permalink
Merge pull request #13 from Atwa/enhancemnt/add_file_extensions
Browse files Browse the repository at this point in the history
fix camera captured file is corrupted
  • Loading branch information
Atwa authored Mar 9, 2023
2 parents b93b67d + 79096c7 commit 9f49288
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
```

Expand Down Expand Up @@ -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. <br /> Feature : Implement camera image picker. |
| 1.0.5 | Feature : Support fragments. <br /> Feature : Implement file picking from initial directory. <br /> 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. |



Expand Down
2 changes: 1 addition & 1 deletion filepicker/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ afterEvaluate {

groupId = 'com.github.atwa'
artifactId = 'filepicker'
version = '1.0.6'
version = '1.0.7'
}
}
repositories {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down

0 comments on commit 9f49288

Please sign in to comment.