lexluthors / compresstools-android Goto Github PK
View Code? Open in Web Editor NEW安卓图片压缩,尽可能保证图片质量,清晰度的压缩。
安卓图片压缩,尽可能保证图片质量,清晰度的压缩。
CompressTools.newBuilder(mView.getContext())
.setKeepResolution(true)
.setBitmapFormat(Bitmap.CompressFormat.PNG)
.setDestinationDirectoryPath(FileManager.getInstance().getPicDirPath())
.setQuality(70)
.build()
.compressToFile(file, new CompressTools.OnCompressListener() {
@Override
public void onStart() {
Log.d("TAG", "onStart: ");
}
@Override
public void onFail(String error) {
Log.e(TAG, "onFail: " + error);
}
@Override
public void onSuccess(File file) {
LogUtil.d("压缩后" + file.length() / 1024);
}
});
其中 FileManager.getInstance().getPicDirPath() 经log为/storage/emulated/0/Android/data/com.xxx.xxx/cache/pic
应无权限问题,已在该目录下成功写入多个文件
看了一下代码 CompressTools类中的generateFilePath方法没有使用给定的fileName,而是使用的系统时间戳作为文件名,代码如下:
private static String generateFilePath(Context context, String parentPath, Uri uri, String extension, String prefix, String fileName) {
File file = new File(parentPath);
if (!file.exists()) {
file.mkdirs();
}
return file.getAbsolutePath() + File.separator + System.currentTimeMillis() + "." + extension;
}
我打算做一个安卓同屏的项目,想使用webp来减少带宽,只是这个项目提供的api都有IO操作,
一次编码的时间在200-300毫秒左右,速度已经很快了,我觉得如果没有IO可能会更快,希望作者考虑一下。
请问有64位架构的so库吗?万分感谢
是不是 FileProvider 的问题。查一下吧~
图片本地文件压缩,没有走成功回调方法
retrofit在上传多图的时候压缩 会先触发请求 再进行压缩 导致请求不能第一时间拿到压缩后的图片
请问是否支持无损压缩,无损压缩比例大概为多少?
/**
* description:
* author: liujie
* date: 2017/8/22 18:19
*/
public void compressToFileJni(final File file, final OnCompressListener mOnCompressListener)
{
FileUtil.runOnSubThread(new Runnable()
{
@OverRide
public void run()
{
BitmapUtil.compressImageJni(context, Uri.fromFile(file), maxWidth, maxHeight, compressFormat, bitmapConfig, quality, destinationDirectoryPath,
fileNamePrefix, fileName, optimize, keepResolution, mOnCompressListener);
}
});
}
这段代码里面BitmapUtil.compressImageJni的参数Uri使用了Uri.fromFile(file)没有考虑Android7.0的情况吧
使用第三方图片选择框架时 (比如知乎的matisse) 一直无法找到路径
CompressTools.newBuilder(this)
.setMaxHeight(1920)
.setMaxWidth(1080)
.setQuality(60)
.setFileName(System.currentTimeMillis() + "_compress")
.setDestinationDirectoryPath(SAVE_PATH)
.build()
.compressToFile(file, new CompressTools.OnCompressListener() {
@OverRide
public void onStart() {
Log.d("xx", "compressPic----" + "onStart"+ file.length());
}
@Override
public void onFail(String error) {
Log.d("xx", "compressPic----" + "onFail");
}
@Override
public void onSuccess(File f) {
Log.d("xx", "compressPic----" + "onSuccess----" + f.length());
upFile = f;
}
});
回调只有onStart()返回了
如题。
W/ExifInterface: Invalid image: ExifInterface got an unsupported image format file(ExifInterface supports JPEG and some RAW image formats only) or a corrupted JPEG file to ExifInterface.
java.io.IOException: Invalid marker: 89
at android.media.ExifInterface.getJpegAttributes(ExifInterface.java:1852)
at android.media.ExifInterface.loadAttributes(ExifInterface.java:1485)
at android.media.ExifInterface.(ExifInterface.java:1122)
at news.jaywei.com.compresslib.BitmapUtil.getScaledBitmap(BitmapUtil.java:172)
at news.jaywei.com.compresslib.BitmapUtil.compressImageJni(BitmapUtil.java:217)
at news.jaywei.com.compresslib.CompressTools$1.run(CompressTools.java:87)
at java.lang.Thread.run(Thread.java:776)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.