Giter Club home page Giter Club logo

tcompress's Introduction

TCompress

Hello,这是一个Android图片压缩库

压缩方面:尺寸、采样、质量三个方面进行压缩
优化:三星等部分手机的图片角度处理
扩展:压缩后图片最大宽高设定(压缩后尺寸接近设定最大值)、质量、格式、配置设定

预览图:


创建对象:

        //可以构造者方式设置,也可以创建对象设置属性值(不设定采用默认配置)
        TCompress tCompress = new TCompress.Builder()
                .setMaxWidth(700)
                .setMaxHeight(900)
                .setQuality(80)
                .setFormat(Bitmap.CompressFormat.JPEG)
                .setConfig(Bitmap.Config.RGB_565)
                .build();
        //  TCompress tCompress = new TCompress();
        //  tCompress.setConfig(Bitmap.Config.RGB_565);
        //  tCompress.setFormat(Bitmap.CompressFormat.WEBP);
        //  tCompress.setQuality(80);
        //  tCompress.setMaxWidth(800);
        //  tCompress.setMaxHeight(800);

同步压缩图片:

        //支持四种压缩转化,文件、Bitmap到压缩后的文件、Bitmap
        File compressedFile = tCompress.compressedToFile(mFile);
        
        if (compressedFile == null) {
            //请查看文件权限问题(其他问题基本不存在,可以查看日志详情)
            return;
        }
        showData(compressedFile);

        //另外三种
        File compressedFile1 = tCompress.compressedToFile(mBitmap);
        Bitmap compressedBitmap = tCompress.compressedToBitmap(mFile);
        Bitmap compressedBitmap1 = tCompress.compressedToBitmap(mBitmap);

      


异步压缩图片:

        //泛型设置回调方法第二个参数类型。如果不指定泛型,也可以根据方法名的ToFile、ToBitmap进行强转
        //文件压缩到指定文件
        tCompress.compressToFileAsync(mFile, new OnCompressListener<File>() {
            //非抽象方法,可选监听 默认不重写
            @Override
            public void onCompressStart() {
            //   showToast("开始压缩");
            }

            //抽象方法,必选监听   默认重写
            @Override
            public void onCompressFinish(boolean success, File file) {
                if (success) {
                    showData(file);
                }
                else {
                    //请查看文件权限问题(其他问题基本不存在,可以查看日志详情)
                }
            }
        });
        //----------------其他三种异步压缩类似-------------
        //  otherThreeAsync();

具体细节用法,下载查看Demo

模板依赖:  项目里面的tcompress模板

gradle依赖:   compile 'com.jkt:tcompress:1.2.3'

tcompress's People

Contributors

holdmyown avatar

Watchers

 avatar  avatar

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.