Tiny
介绍:
一个图片压缩框架。
运行效果:
使用说明:
安装
compile 'com.zxy.android:tiny:${LAST_VERSION}'
选择一个abi
Tiny 提供的 abi:armeabi、armeabi-v7a、arm64-v8a、x86.
选择你需要的"abi" 版本:
android {
defaultConfig {
ndk {
abiFilters 'armeabi-v7a','x86'//or armeabi、arm64-v8a、x86
}
}
}
初始化
Tiny.getInstance().init(this);
压缩为Bitmap
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
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
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
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
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
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
}
});
Tiny与微信朋友圈的压缩率比较
下面是使用Tiny图片压缩库进行压缩的效果对比示例:
图片信息 | Tiny | |
---|---|---|
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) |
相关文章:
已下载
0