Coder Social home page Coder Social logo

compresstools-android's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

compresstools-android's Issues

创建文件失败

 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
应无权限问题,已在该目录下成功写入多个文件

fileName的设置无效

看了一下代码 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;
    }

创建文件失败

image
这个问题怎么解决,权限都是有的,是不是你的代码有问题,看了回复的压根没有提出解决方案

压缩图片没有走onSuccess的回调,压缩失败没有onCompressFailed()回调

/**
* 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的情况吧

压缩不成功

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()返回了

在华为mate8(Android7.0)会有warning:ExifInterface got an unsupported image format file(ExifInterface supports JPEG and some RAW image formats only) or a corrupted JPEG file to ExifInterface.

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.