GithubHelp home page GithubHelp logo

fixedyangsir / advancedluban Goto Github PK

View Code? Open in Web Editor NEW

This project forked from shaohui10086/advancedluban

0.0 1.0 0.0 118 KB

高效、简洁的图片压缩工具库 / An Advanced version based on Luban

Home Page: http://shaohui.me

License: Apache License 2.0

Java 100.00%

advancedluban's Introduction

AdvancedLuban

build license

Luban(鲁班) —— Android图片压缩工具,仿微信朋友圈压缩策略。

AdvancedLuban —— 在Luban的基础上根据一些需求, 进行了扩展, 增加了一些新特性,自定义压缩,多图同步压缩,专注更好的图片压缩体验

Import

Maven

<dependency>
  <groupId>me.shaohui.advancedluban</groupId>
  <artifactId>library</artifactId>
  <version>1.1</version>
  <type>pom</type>
</dependency>

or Gradle

compile 'me.shaohui.advancedluban:library:1.1'

Usage

Listener方式

Luban内部采用IO线程进行图片压缩,外部调用只需设置好结果监听即可:

Luban.get(this)                     // 初始化Luban
    .load(File)                     // 传人要压缩的图片
    .putGear(Luban.THIRD_GEAR)      // 设定压缩模式,默认 THIRD_GEAR
    .launch(listener);              // 启动压缩并设置监听

RxJava方式

RxJava调用方式同样默认IO线程进行压缩,可在任意线程观察:

Luban.get(this)                                     
        .load(file)                               
        .putGear(Luban.CUSTOM_GEAR)                 
        .asObservable()                             // 生成Observable
        .subscribe(successAction, errorAction)      // 订阅压缩事件

压缩模式

1. CUSTOM_GEAR

AdvancedLuban增加的个性化压缩,根据限制要求对图片进行压缩,可以限制:图片的宽度、高度以及图片文件的大小

    Luban.get(this)
            .load(mFile)
            .setMaxSize(500)                // 限制最终图片大小(单位:Kb)
            .setMaxHeight(1920)             // 限制图片高度
            .setMaxWidth(1080)              // 限制图片宽度
            .putGear(Luban.CUSTOM_GEAR)     // 使用 CUSTOM_GEAR 压缩模式
            .asObservable()

2. THIRD_GEAR

Luban的主要功能,提供了类似微信的压缩效果,适用于普通压缩,没有文件大小限制以及图片的宽高限制

3. FIRST_GEAR

THIRD_GEAR的简化版本,压缩之后的图片分辨率小于 1280 x 720, 文件最后小于60Kb,特殊情况下,小于原图片的1/5,适用于快速压缩,不计较最终图片品质

多图同步压缩

如果你选择的调用方式的是Listener方式:

    Luban.get(this)
            .putGear(Luban.CUSTOM_GEAR)             
            .load(fileList)                     // 加载所有图片
            .launch(multiCompressListener);     // 传入一个 OnMultiCompressListener 

RxJava 方式:

    Luban.get(this)
            .putGear(Luban.CUSTOM_GEAR)             
            .load(fileList)                     // 加载所有图片
            .asListObservable()                 // 生成Observable<List> 返回压缩成功的所有图片结果

Issue

大家可以根据自己的需求选择不同的压缩模式以及调用方式 b( ̄▽ ̄)d !最后,欢迎大家提Issue

Thanks For

License

Copyright 2016 shaohui10086

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

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.