一款易用的 Android 图片压缩框架

License Version Code Grade Build Min Sdk Version Author QQ Group

更高级的 Android 图片压缩库,支持自定义: - 图片类型 (Uri/File/bitmap/Byte 数组/自定义) - 结果类型 (Bitmap/File) - 任务执行模式 (阻塞/RxJava/Kotlin 协程/AsyncTask) - 压缩算法 要使用该库,首先添加 maven central 仓库, ```gradle repositories { mavenCentral() } ``` 然后添加该项目的依赖, ```gradle implementation 'com.github.Shouheng88:compressor:latest-version' ``` 示例:以压缩 Uri 图片、获取 File 类型的结果、在 Kotlin 协程中启动为例。整个代码是, ```kotlin GlobalScope.launch { val result = Compress.with(context, file.uri(context)) .setQuality(80) .concrete { withMaxWidth(100f) withMaxHeight(100f) withScaleMode(ScaleMode.SCALE_HEIGHT) withIgnoreIfSmaller(true) } .get(Dispatchers.IO) withContext(Dispatchers.Main) { Glide.with(context).load(result).into(binding.iv6) } } ``` 该库允许你对多个地方进行自定义, - 了解更多使用方式,请阅读 [示例工程](sample/app/src/main/java/me/shouheng/sample/view/SampleActivity.kt). - 了解如何自定义图片压缩算法,请阅读 [自定义算法示例](sample/app/src/main/java/me/shouheng/sample/custom/AlwaysHalfAlgorithm.kt). - 了解如何自定义图片类型,请阅读 [自定义图片类型示例](sample/app/src/main/java/me/shouheng/sample/custom/AssetsResourceSource.kt). ## License ``` Copyright (c) 2019-2021 Shouheng Wang. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ```