public class LubanCompressUtils {
//压缩文件存放路径
final static String STOREPATH = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "shop";
/**
* 压缩文件
* @param filePath 本地文件路径
* @param compressListener
*/
public static void compressFile(String filePath,OnCompressListener compressListener){
File file = new File(filePath);
Log.e("Luban", "file "+file.getPath() +" "+file.length());
File directory = new File(STOREPATH);
if(!directory.exists()){
directory.mkdir();
}
if(file.length() > 1024*1024/2){//是否大于500k
Luban.with(this)
.load(file) // 传人要压缩的图片列表
.ignoreBy(100) // 忽略不压缩图片的大小
.setTargetDir(STOREPATH) // 设置压缩后文件存储位置
.setCompressListener(compressListener)/*设置回调*/
.launch(); //启动压缩
}else {
compressListener.onSuccess(file);
}
}