diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a915d3a..5aab6a51 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] +## [1.7.4] - 2020-08-02 +### Changed + * Fixed PNG image saved as JPG after compress issue [#105](https://github.com/Dhaval2404/ImagePicker/issues/105) ## [1.7.3] - 2020-07-18 ### Changed @@ -73,6 +76,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * Retrieve Image Result as File, File Path as String or Uri object [Unreleased]: https://github.com/Dhaval2404/ImagePicker/compare/v2.0...HEAD +[1.7.4]: https://github.com/Dhaval2404/ImagePicker/compare/v1.7.3...v1.7.4 [1.7.3]: https://github.com/Dhaval2404/ImagePicker/compare/v1.7.2...v1.7.3 [1.7.2]: https://github.com/Dhaval2404/ImagePicker/compare/v1.7.1...v1.7.2 [1.7.1]: https://github.com/Dhaval2404/ImagePicker/compare/v1.7...v1.7.1 diff --git a/README.md b/README.md index a6bcf119..5bdccc8e 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ Almost 90% of the app that I have developed has an Image upload feature. Along w ``` ```groovy - implementation 'com.github.dhaval2404:imagepicker:1.7.3' + implementation 'com.github.dhaval2404:imagepicker:1.7.4' ``` **If you are yet to Migrate on AndroidX, Use support build artifact:** @@ -116,10 +116,10 @@ Almost 90% of the app that I have developed has an Image upload feature. Along w imgProfile.setImageURI(fileUri) //You can get File object from intent - val file:File = ImagePicker.getFile(data) + val file:File = ImagePicker.getFile(data)!! //You can also get File Path from intent - val filePath:String = ImagePicker.getFilePath(data) + val filePath:String = ImagePicker.getFilePath(data)!! } else if (resultCode == ImagePicker.RESULT_ERROR) { Toast.makeText(this, ImagePicker.getError(data), Toast.LENGTH_SHORT).show() } else { @@ -276,6 +276,7 @@ Almost 90% of the app that I have developed has an Image upload feature. Along w * Fixed NullPointerException in FileUriUtils.getPathFromRemoteUri() [#61](https://github.com/Dhaval2404/ImagePicker/issues/61) (Special Thanks to [himphen](https://github.com/himphen)) * Fixed UCropActivity Crash Android 4.4 (KiKat) [#82](https://github.com/Dhaval2404/ImagePicker/issues/82) * Fixed PNG image saved as JPG after crop issue [#94](https://github.com/Dhaval2404/ImagePicker/issues/94) + * Fixed PNG image saved as JPG after compress issue [#105](https://github.com/Dhaval2404/ImagePicker/issues/105) ### Version: 1.6 diff --git a/imagepicker/build.gradle b/imagepicker/build.gradle index 19cadbe8..8476a7d1 100644 --- a/imagepicker/build.gradle +++ b/imagepicker/build.gradle @@ -13,8 +13,8 @@ android { defaultConfig { minSdkVersion 19 targetSdkVersion 28 - versionCode 11 - versionName "1.7.3" + versionCode 12 + versionName "1.7.4" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } @@ -72,7 +72,7 @@ ext { siteUrl = 'https://github.com/Dhaval2404/ImagePicker/' gitUrl = 'https://github.com/Dhaval2404/ImagePicker.git' - libraryVersion = '1.7.3' + libraryVersion = '1.7.4' //If you are uploading new library try : gradlew install //If you are updating existing library then execute: gradlew bintrayUpload //In both the case don't forgot to put bintray credentials in local.properties file. diff --git a/imagepicker/src/main/kotlin/com/github/dhaval2404/imagepicker/provider/CompressionProvider.kt b/imagepicker/src/main/kotlin/com/github/dhaval2404/imagepicker/provider/CompressionProvider.kt index afa6cbf2..05dc72cb 100644 --- a/imagepicker/src/main/kotlin/com/github/dhaval2404/imagepicker/provider/CompressionProvider.kt +++ b/imagepicker/src/main/kotlin/com/github/dhaval2404/imagepicker/provider/CompressionProvider.kt @@ -6,6 +6,7 @@ import android.graphics.BitmapFactory import android.os.AsyncTask import com.github.dhaval2404.imagepicker.ImagePicker import com.github.dhaval2404.imagepicker.ImagePickerActivity +import com.github.dhaval2404.imagepicker.util.FileUriUtils import com.github.dhaval2404.imagepicker.util.FileUtil import com.github.dhaval2404.imagepicker.util.ImageUtil import java.io.File @@ -169,13 +170,14 @@ class CompressionProvider(activity: ImagePickerActivity) : BaseProvider(activity // Check file format var format = Bitmap.CompressFormat.JPEG - var quality = 90 + var quality = 100 if (file.absolutePath.endsWith(".png")) { format = Bitmap.CompressFormat.PNG quality = 100 } - val compressFile: File? = FileUtil.getImageFile(dir = mFileDir) + val extension = FileUriUtils.getImageExtension(file) + val compressFile: File? = FileUtil.getImageFile(dir = mFileDir, extension = extension) return if (compressFile != null) { ImageUtil.compressImage( file, maxWidth.toFloat(), maxHeight.toFloat(), diff --git a/imagepicker/src/main/kotlin/com/github/dhaval2404/imagepicker/util/FileUriUtils.kt b/imagepicker/src/main/kotlin/com/github/dhaval2404/imagepicker/util/FileUriUtils.kt index 8b81ab1e..bd13d8a5 100644 --- a/imagepicker/src/main/kotlin/com/github/dhaval2404/imagepicker/util/FileUriUtils.kt +++ b/imagepicker/src/main/kotlin/com/github/dhaval2404/imagepicker/util/FileUriUtils.kt @@ -180,7 +180,10 @@ object FileUriUtils { return if (success) file!!.path else null } - /** @return extension of image with dot, or default .jpg if it none. + /** + * Get Image Extension i.e. .png, .jpg + * + * @return extension of image with dot, or default .jpg if it none. */ fun getImageExtension(uriImage: Uri): String { var extension: String? = null @@ -202,6 +205,15 @@ object FileUriUtils { return ".$extension" } + /** + * Get Image Extension i.e. .png, .jpg + * + * @return extension of image with dot, or default .jpg if it none. + */ + fun getImageExtension(file: File): String { + return getImageExtension(Uri.fromFile(file)) + } + /** * @param uri The Uri to check. * @return Whether the Uri authority is ExternalStorageProvider. diff --git a/sample/build.gradle b/sample/build.gradle index d8f76a47..c43f75e1 100644 --- a/sample/build.gradle +++ b/sample/build.gradle @@ -12,8 +12,8 @@ android { applicationId "com.github.dhaval2404.imagepicker.sample" minSdkVersion 19 targetSdkVersion 28 - versionCode 11 - versionName "1.7.3" + versionCode 12 + versionName "1.7.4" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true }