为了简化对图片压缩的调用,提供最简洁与合理的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图片压缩库进行压缩的效果对比示例:

图片信息 Tiny Wechat
6.66MB (3500x2156) 151KB (1280x788) 135KB (1280x789)
4.28MB (4160x3120) 219KB (1280x960) 195KB (1280x960)
2.60MB (4032x3024) 193KB (1280x960)) 173KB (1280x960)
372KB (500x500) 38.67KB (500x500) 34.05KB (500x500)
236KB (960x1280) 127KB (960x1280) 118KB (960x1280)

压缩为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
}
});

 

最新文章

  1. [.net 面向对象程序设计进阶] (12) 序列化(Serialization)(四) 快速掌握JSON的序列化和反序列化
  2. Java多线程学习(二)
  3. 报表控件NCreport教程:子查询系统设计
  4. Linux 查看磁盘空间大小
  5. sql group by
  6. MySQL存储过程解析
  7. #define XXX do{...}while(0)
  8. What is the Best Programming Language to Learn in 2014?
  9. (转)博弈问题与SG函数
  10. Lazy Math Instructor
  11. Firefox Profile
  12. 互联网视频直播技术(广电总局、优酷土豆、XX直播)
  13. 原创《如何用vue来轻松的驾驭 html5 webapp的页面体验》
  14. 21 go并发编程-下
  15. Adobe Flash Builder 4.6 打开时提示Failed to create the Java Virtual Machine
  16. PAT 1026 Table Tennis[比较难]
  17. c++之boost share_ptr
  18. html基础-from表单(5)
  19. LoadRunner FAQ2
  20. php 中的 short_open_tag 的作用

热门文章

  1. hdu 4927 java程序
  2. [证书服务器 第二篇] 基于OpenSSL 在 CentOS6 系统上 搭建自签证书服务,并应用于Web容器
  3. PYTHON加密解密字符串
  4. PermissionError: [Errno 13] Permission denied:
  5. 一次react滚动列表的实践---兼容ios安卓
  6. ManualResetEvent使用
  7. Hotel California
  8. ACM学习历程——HDU4472 Count(数学递推) (12年长春区域赛)
  9. QT(1)介绍
  10. Vijos1221:神秘的配方