Android图片压缩框架-Tiny 集成(抄来的,防止网页没有了,搬到自己家里)
来源:互联网 发布:c语言e语言 编辑:程序博客网 时间:2024/04/30 18:43
为了简化对图片压缩的调用,提供最简洁与合理的api压缩逻辑,对于压缩为Bitmap根据屏幕分辨率动态适配最佳大小,对于压缩为File优化底层libjpeg
的压缩,整个图片压缩过程全在压缩线程池中异步压缩,结束后分发回UI线程。
支持的压缩类型
Tiny
图片压缩框架支持的压缩数据源类型:
1、Bytes
2、File
3、Bitmap
4、Stream
5、Resource
6、Uri(network、file、content)
Tiny
支持单个数据源压缩以及批量压缩,支持的压缩类型:
1、数据源—>压缩为Bitmap
2、数据源—>压缩为File
3、数据源—>压缩为File并返回压缩后的Bitmap
4、批量数据源—>批量压缩为Bitmap
5、批量数据源—>批量压缩为File
6、批量数据源—>批量压缩为File并返回压缩后Bitmap
压缩参数
Tiny.BitmapCompressOptions
Bitmap压缩参数可配置三个:
1、width
2、height
3、Bitmap.Config
如果不配置,Tiny
内部会根据屏幕动态适配以及默认使用ARGB_8888
Tiny.FileCompressOptions
File压缩参数可配置四个:
1、quality-压缩质量,默认为76
2、isKeepSampling-是否保持原数据源图片的宽高
3、fileSize-压缩后文件大小
4、outfile-压缩后文件存储路径
如果不配置,Tiny
内部会根据默认压缩质量进行压缩,压缩后文件默认存储在:ExternalStorage/Android/data/${packageName}/tiny/目录下
Tiny项目地址: https://github.com/tianyingzhong/Tiny
Tiny与微信朋友圈的压缩率比较
下面是使用Tiny图片压缩库进行压缩的效果对比示例:
压缩为Bitmap
1
2
3
4
5
6
7
Tiny.BitmapCompressOptions options = new Tiny.BitmapCompressOptions();
Tiny.getInstance().source("").asBitmap().withOptions(options).compress(new BitmapCallback() {
@Override
public void callback(boolean isSuccess, Bitmap bitmap) {
//return the compressed bitmap object
}
});
压缩为File
1
2
3
4
5
6
7
Tiny.FileCompressOptions options = new Tiny.FileCompressOptions();
Tiny.getInstance().source("").asFile().withOptions(options).compress(new FileCallback() {
@Override
public void callback(boolean isSuccess, String outfile) {
//return the compressed file path
}
});
压缩为File并返回Bitmap
1
2
3
4
5
6
7
Tiny.FileCompressOptions options = new Tiny.FileCompressOptions();
Tiny.getInstance().source("").asFile().withOptions(options).compress(new FileWithBitmapCallback() {
@Override
public void callback(boolean isSuccess, Bitmap bitmap, String outfile) {
//return the compressed file path and bitmap object
}
});
批量压缩为Bitmap
1
2
3
4
5
6
7
Tiny.BitmapCompressOptions options = new Tiny.BitmapCompressOptions();
Tiny.getInstance().source("").batchAsBitmap().withOptions(options).batchCompress(new BitmapBatchCallback() {
@Override
public void callback(boolean isSuccess, Bitmap[] bitmaps) {
//return the batch compressed bitmap object
}
});
批量压缩为File
1
2
3
4
5
6
7
Tiny.FileCompressOptions options = new Tiny.FileCompressOptions();
Tiny.getInstance().source("").batchAsFile().withOptions(options).batchCompress(new FileBatchCallback() {
@Override
public void callback(boolean isSuccess, String[] outfile) {
//return the batch compressed file path
}
});
批量压缩为File并返回Bitmap
1
2
3
4
5
6
7
Tiny.FileCompressOptions options = new Tiny.FileCompressOptions();
Tiny.getInstance().source("").batchAsFile().withOptions(options).batchCompress(new FileWithBitmapBatchCallback() {
@Override
public void callback(boolean isSuccess, Bitmap[] bitmaps, String[] outfile) {
//return the batch compressed file path and bitmap object
}
});
阅读全文
0 0
- Android图片压缩框架-Tiny 集成(抄来的,防止网页没有了,搬到自己家里)
- Android图片压缩框架-Tiny
- 人家那里抄来的,自己又写了点
- 抄了一个简短的Tiny Web服务器
- 几个Linux函数(很久的整理了,从自己的新浪博客搬来)
- 搬家了,搬到CSDN来...
- 防止别人将自己的网页放在框架中
- 用GTmetrix来优化你的网页(集成了YSlow、FireBug的功能)
- 用GTmetrix来优化你的网页(集成了YSlow、FireBug的功能)
- 用GTmetrix来优化你的网页(集成了YSlow、FireBug的功能)
- ftp 搭建抄来的自己在完善点
- 厉害了!家里来了黑科技
- 今天我终于把我天涯blog的文章搬到这里来了!!!庆祝庆祝!
- 搬到自己的空间了http://www.linkstudio.com.cn/xblog/
- 抄来的(打工与创业)
- 抄来的
- 抄来的
- 随手抄来的
- centos 6.8 + pgsql 9.6 + pg_buffercache
- ContOS 安装jdk
- Java知识点笔记--构造器内部的多态行为
- OpenCV界面(CVUI,跨平台,比QT方便,包括按钮等)
- 单例模式
- Android图片压缩框架-Tiny 集成(抄来的,防止网页没有了,搬到自己家里)
- 图片处理工具-局部像素替换
- Java -D 属性获得
- Java正则表达式特点
- pandas将多个excel合并至一个DataFrame
- Tomcat源码分析--资源映射器Mapper
- angular.copy()功能学习
- 程序员的自我修养之Windows下的动态链接
- HTML5的新标签