TaiShan - 图片压缩算法


Apache
跨平台
Java

软件简介

TaiShan

Luban 的重构版本,感谢 Luban 作者提供的算法,此项目中含有大量 Luban 的原始代码。

本人只做了整体架构的重构。

原地址:https://github.com/Curzibn/Luban

与Luban的差异

  1. 抽离 RxJava,方便非 RxJava 项目的使用。

  2. 可直接压缩 Bitmap,压缩过程中不产生临时文件。

  3. 修复同时压缩多个图片,回调冲突 bug。

  4. 可自定义压缩算法。

使用方法

直接使用

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