一句话轻松实现压缩图片和文件压缩

栏目: 软件资讯 · 发布时间: 8年前

内容简介:一句话轻松实现压缩图片和文件压缩

CompressHelper

压缩,图片压缩,压缩Bitmap,Compress,CompressImage,CompressFile,CompressBitmap

笔者从零搭建 Retrofit & RxJava & MVP 框架APP,欢迎关注: https://github.com/nanchen2251/AiYaGirl

笔者从零搭建 Retrofit & RxJava & MVP 框架APP,欢迎关注: https://github.com/nanchen2251/AiYaGirl

笔者从零搭建 Retrofit & RxJava & MVP 框架APP,欢迎关注: https://github.com/nanchen2251/AiYaGirl

主要通过尺寸压缩和质量压缩,以达到清晰度最优,该项目参考了 https://github.com/zetbaitsu/Compressor 的部分代码,且在基础上修正了部分bug

效果图

一句话轻松实现压缩图片和文件压缩

⊙开源不易,希望给个star或者fork奖励

⊙拥抱开源: https://github.com/nanchen2251/

特点

1、支持压缩单张图片和多张图片

使用方法

1、添加依赖

Step 1. Add it in your root build.gradle at the end of repositories:

allprojects {
		repositories {
			...
			maven { url 'https://jitpack.io' }
		}
	}

Step 2. Add the dependency

dependencies {
	        compile 'com.github.nanchen2251:CompressHelper:1.0.5'
	}

2、在Activity里面使用

  File newFile = CompressHelper.getDefault(this).compressToFile(oldFile);

3、你也可以自定义属性

  File newFile = new CompressHelper.Builder(this)
                    .setMaxWidth(720)  // 默认最大宽度为720
                    .setMaxHeight(960) // 默认最大高度为960
                    .setQuality(80)    // 默认压缩质量为80
		    .setFileName(yourFileName) // 设置你需要修改的文件名
                    .setCompressFormat(CompressFormat.JPEG) // 设置默认压缩为jpg格式
                    .setDestinationDirectoryPath(Environment.getExternalStoragePublicDirectory(
                            Environment.DIRECTORY_PICTURES).getAbsolutePath())
                    .build()
                    .compressToFile(oldFile);

该项目参考了:

关于作者

南尘

四川成都

其它开源

博客园


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Real-Time Rendering, Third Edition

Real-Time Rendering, Third Edition

Tomas Akenine-Moller、Eric Haines、Naty Hoffman / A K Peters/CRC Press / 2008-7-25 / USD 102.95

Thoroughly revised, this third edition focuses on modern techniques used to generate synthetic three-dimensional images in a fraction of a second. With the advent or programmable shaders, a wide varie......一起来看看 《Real-Time Rendering, Third Edition》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试

RGB CMYK 转换工具
RGB CMYK 转换工具

RGB CMYK 互转工具