TaiShan圖片壓縮算法
TaiShan
Luban 的重構版本,感謝 Luban 作者提供的算法,此項目中含有大量 Luban 的原始代碼。
本人只做了整體架構的重構。
原地址:https://github.com/Curzibn/Luban
抽離 RxJava,方便非 RxJava 項目的使用。
可直接壓縮 Bitmap,壓縮過程中不產生臨時文件。
修復同時壓縮多個圖片,回調沖突 bug。
可自定義壓縮算法。
使用方法
直接使用
compile 'com.github.lengyue524.TaiShan:taishan:0.1.3'
private void compressWithAT(Bitmap bitmap) {
CompressTask task = new CompressTask();
task.execute(bitmap);
}
private class CompressTask extends AsyncTask<Bitmap, Object, byte[]> {
@Override
protected byte[] doInBackground(Bitmap... bitmaps) {
return TaiShan.get().load(new BitmapInfo(bitmaps[0])).launch();
}
@Override
protected void onPostExecute(byte[] bytes) {
String path = MainActivity.this.getCacheDir() + File.separator + System.currentTimeMillis();
File file = TaiShan.saveImage(path, bytes);// 保存文件
Bitmap bitmap = TaiShan.toBitmap(bytes);// 轉換為Bitmap
}
}
RxJava
compile 'com.github.lengyue524.TaiShan:taishan:0.1.3' compile 'com.github.lengyue524.TaiShan:rxtaishan:0.1.3
評論
圖片
表情
