Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shouheng88/compressor
An easy to use image compress library for Android.
https://github.com/shouheng88/compressor
android compressor image image-processing luban
Last synced: 2 days ago
JSON representation
An easy to use image compress library for Android.
- Host: GitHub
- URL: https://github.com/shouheng88/compressor
- Owner: Shouheng88
- License: apache-2.0
- Created: 2019-03-11T15:06:53.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2021-12-18T10:49:19.000Z (about 3 years ago)
- Last Synced: 2024-12-29T05:07:14.283Z (9 days ago)
- Topics: android, compressor, image, image-processing, luban
- Language: Kotlin
- Homepage:
- Size: 8.91 MB
- Stars: 602
- Watchers: 11
- Forks: 54
- Open Issues: 0
-
Metadata Files:
- Readme: README-zh.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
一款易用的 Android 图片压缩框架更高级的 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 athttp://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.
```