Android 简单的视频、图片压缩工具

首页需要压缩的工具包

1.Gradle

复制代码
implementation 'com.iceteck.silicompressorr:silicompressor:2.2.3'

2.添加相关权限(手机得动态申请权限)

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

3.使用

使用很简单,直接调用相关方法传入文件路径就能获得压缩之后新文件的路径

<1> 视频压缩(需要在子线程中使用)

压缩视频文件并返回新视频的文件路径(参数传入原视频videoPath和压缩后destinationDirectory存放的文件夹,返回压缩后图片绝对路径)。横屏视频的outWidth宽度 outHeight高度 bitrate比特率(码率)越高数据大 体积越大一般450000

String filePath=SiliCompressor.with(Context).compressVideo(videoPath, destinationDirectory,outWidth,outHeight,bitrate);

String filePath=SiliCompressor.with(Context).compressVideo(videoPath, destinationDirectory);默认

<2> 图片压缩

压缩图像并返回新图像的文件路径

String filePath=SiliCompressor.with(Context).compress(imagePath, destinationDirectory);

压缩图像并在删除源图像时返回新图像的文件路径

String filePath=SiliCompressor.with(Context).compress(imagePath, destinationDirectory,true);

压缩图像可绘制并返回新图像的文件路径

String filePath=SiliCompressor.with(Context).compress(R.drawable.icon);

压缩图像并返回新图像的位图数据

Bitmap imageBitmap=SiliCompressor.with(Context).getCompressBitmap(imagePath);

压缩图像并在删除源图像的同时返回新图像的位图数据

Bitmap imageBitmap=SiliCompressor.with(Context).getCompressBitmap(imagePath,true)

好啦,先记录到这吧!

相关推荐
阿巴斯甜4 分钟前
必看11
android
solo_997 分钟前
Perftto 使用命令添加标签
android
阿巴斯甜14 分钟前
必看10
android
阿巴斯甜17 分钟前
必看9
android
阿巴斯甜37 分钟前
必看6
android
angerdream1 小时前
Android手把手编写儿童手机远程监控App之SQLite详解
android
阿巴斯甜1 小时前
必看5
android
雪铃儿2 小时前
Shorebird 之外,Flutter Android 热更新还有什么选择
android·前端
张筱竼3 小时前
Android开发中的MVC、MVP与MVVM详解
android
阿巴斯甜5 小时前
必看4
android