Curzibn / Luban

Luban(鲁班)—Image compression with efficiency very close to WeChat Moments/可能是最接近微信朋友圈的图片压缩算法
Apache License 2.0
13.58k stars 2.25k forks source link

api 29 无法压缩 #383

Open Liangwenb opened 4 years ago

Liangwenb commented 4 years ago

获取到图标uri也是无法压缩的, 除非把文件复制到私有目录

private File compress(Context context, InputStreamProvider path) throws IOException { File result;

File outFile = getImageCacheFile(context, Checker.SINGLE.extSuffix(path));

if (mRenameListener != null) {
  String filename = mRenameListener.rename(path.getPath());
  outFile = getImageCustomFile(context, filename);
}

if (mCompressionPredicate != null) {
  if (mCompressionPredicate.apply(path.getPath())
      && Checker.SINGLE.needCompress(mLeastCompressSize, path.getPath())) {
    result = new Engine(path, outFile, focusAlpha).compress();
  } else {
    result = new File(path.getPath());
  }
} else {
  result = Checker.SINGLE.needCompress(mLeastCompressSize, path.getPath()) ?
      new Engine(path, outFile, focusAlpha).compress() :
      new File(path.getPath());
}

return result;
}

boolean needCompress(int leastCompressSize, String path) { if (leastCompressSize > 0) { File source = new File(path); return source.exists() && source.length() > (leastCompressSize << 10); } return true; }

非常希望作者能继续维护这个库.

Love667767 commented 4 years ago

刚接入了,也发现了这个问题。这个判断文件是否存在的代码得改一下。 我在 InputStreamProvider 接口新增了一个方法,通过流获取大小。 @Override public long getInputStreamSize() throws IOException { return inputStream == null ? 0 : inputStream.available(); }

ziyouxiaozi commented 3 years ago

刚接入了,也发现了这个问题。这个判断文件是否存在的代码得改一下。 我在 InputStreamProvider 接口新增了一个方法,通过流获取大小。 @override public long getInputStreamSize() throws IOException { return inputStream == null ? 0 : inputStream.available(); }

这个方法在哪具体怎么使用呀?