android bitmapfun.zip,Compressor:一个Android图像压缩库

Compressor

68747470733a2f2f696d672e736869656c64732e696f2f62616467652f416e64726f6964253230417273656e616c2d436f6d70726573736f722d626c75652e7376673f7374796c653d666c617468747470733a2f2f7472617669732d63692e6f72672f7a65746261697473752f436f6d70726573736f722e7376673f6272616e63683d6d617374657268747470733a2f2f636f6465636f762e696f2f67682f7a65746261697473752f436f6d70726573736f722f6272616e63682f6d61737465722f67726170682f62616467652e737667

4565ac5455bd042f216d612aa85dc1e6.png Compressor is a lightweight and powerful android image compression library. Compressor will allow you to compress large photos into smaller sized photos with very less or negligible loss in quality of the image.

Gradle

dependencies {

implementation 'id.zelory:compressor:3.0.0'

}

Let's compress the image size!

Compress Image File

val compressedImageFile = Compressor.compress(context, actualImageFile)

Compress Image File to specific destination

val compressedImageFile = Compressor.compress(context, actualImageFile) {

default()

destination(myFile)

}

I want custom Compressor!

Using default constraint and custom partial of it

val compressedImageFile = Compressor.compress(context, actualImageFile) {

default(width = 640, format = Bitmap.CompressFormat.WEBP)

}

Full custom constraint

val compressedImageFile = Compressor.compress(context, actualImageFile) {

resolution(1280, 720)

quality(80)

format(Bitmap.CompressFormat.WEBP)

size(2_097_152) // 2 MB

}

Using your own custom constraint

class MyLowerCaseNameConstraint: Constraint {

override fun isSatisfied(imageFile: File): Boolean {

return imageFile.name.all { it.isLowerCase() }

}

override fun satisfy(imageFile: File): File {

val destination = File(imageFile.parent, imageFile.name.toLowerCase())

imageFile.renameTo(destination)

return destination

}

}

val compressedImageFile = Compressor.compress(context, actualImageFile) {

constraint(MyLowerCaseNameConstraint()) // your own constraint

quality(80) // combine with compressor constraint

format(Bitmap.CompressFormat.WEBP)

}

You can create your own extension too

fun Compression.lowerCaseName() {

constraint(MyLowerCaseNameConstraint())

}

val compressedImageFile = Compressor.compress(context, actualImageFile) {

lowerCaseName() // your own extension

quality(80) // combine with compressor constraint

format(Bitmap.CompressFormat.WEBP)

}

Compressor now is using Kotlin coroutines!

Calling Compressor should be done from coroutines scope

// e.g calling from activity lifecycle scope

lifecycleScope.launch {

val compressedImageFile = Compressor.compress(context, actualImageFile)

}

// calling from global scope

GlobalScope.launch {

val compressedImageFile = Compressor.compress(context, actualImageFile)

}

Run Compressor in main thread

val compressedImageFile = Compressor.compress(context, actualImageFile, Dispatchers.Main)

Old version

Please read this readme

License

Copyright (c) 2016 Zetra.

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.

Common4Android一个通用Android工具,包含网络、线程管理器、常用Util工具、热修复,它拥有良好的架构,低耦合、高内聚,使用起来非常轻松。 -基类 ClassName Description BaseApplication.java Application基类,启动SDCard监听、网络状态监听。 BaseActiivty.java Activity基类,封装常用方法及Activity管理。 -管理器 ClassName Description ActivityManager.java Activity管理工具类,可以获得当前引用启动的Activity实例。 HotFixManager.java 热修复patch加载工具类。 LRUCache.java LRUCache。 ThreadPoolManager.java 应用线程池管理。 -网络处理 ClassName Description HttpTag.java Api接口配置类。 TaskManager.java 网络任务管理类。 HttpDataRequest.java 通用请求类。 HttpPostRequest.java Post请求类。 -工具类 ClassName Description AnimationUtil.java 动画效果工具类,提供缩放、透明度、位移、旋转动画方法。 AppInfoUtil.java 应用信息工具类,获取应用版本号、版本编码。 BitmapCacheUtil.java Bitmap缓存工具类,封装bitmap本地存储方法。 BitmapEffectUtil.java Bitmap特效实现类,封装bitmap特效实现方法,如:老照片、RGB偏移等。 BitmapUtil.java Bitmap常用工具类,Bitmap数据类型转换、圆角、缩放、倒影。 ConvertUtil.java 转换工具类,进行对象的类型转换。 DateUtil.java 日期工具类,日期转换生肖、日期转换星座、日期相互转换。 DesUtil.java DES加密工具类。 DeviceUtil.java 设备信息获取工具类,获得设备型号、设备生产厂商、屏幕尺寸、GPS状态、wifi状态等。 DialogUtil.java 弹窗工具类,ProgressDialog,AlertDialog,Toast弹出封装。 FileUtil.java 文件工具类,文件常用方法,获得文件大小、文件大小转换。 MD5Util.java MD5加密工具类。 RegexUtil.java 常用正则表达式工具类。 SDCardUtil.java SD卡信息管理工具类。 SharedPreferencesUtil.java SharedPreferences工具类。 StringUtil.java 字符串处理工具类。 SystemIntentUtil.java 系统Intent工具类,常用的系统Intent跳转函数,如:打电话、发短信等。 示例代码: - NetWork HttpDataRequest request = new HttpDataRequest(); request.setTag(HttpTag.TEST); request.setSort(Constants.REQUEST_METHOD_GET); request.setGzip(true); request.setRetry(false); request.setNeedAuth(false); TaskManager.startHttpDataRequset(request, new HttpDataResponse() {     @Override     public void onHttpRecvOK(HttpTag tag, Object extraInfo, Object result) {         DialogUtil.showToast(MainActivity.this, (String) result, Toast.LENGTH_LONG);     }     @Override     public void onHttpRecvError(HttpTag tag, HttpCode retCode, String msg) {         DialogUtil.showToast(MainActivity.this, "onHttpRecvError retCode:"   retCode   " msg:"   msg, Toast.LENGTH_LONG);     }     @Override     public void onHttpRecvCancelled(HttpTag tag) {         DialogUtil.showToast(MainActivity.this, "onHttpRecvCancelled", Toast.LENGTH_LONG);     } });
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值