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)

好啦,先记录到这吧!

相关推荐
好的佩奇6 小时前
Dart 之 JSON
android·flutter·dart
_祝你今天愉快7 小时前
Android 事件传递机制:[一] 事件分发机制详解
android
Digitally12 小时前
如何将电脑上的联系人传输到安卓手机(4 种方法)
android
Carson带你学Android19 小时前
移动开发周报 :一句话出 App、低端机跑 Gemini、手机写代码
android·ai编程
恋猫de小郭19 小时前
站起来,Flutter 要支持真正的 3D Texture 了
android·前端·flutter
FungLeo1 天前
FengCMS · PHP+MySQL 升级实录 · 留言模块的六项问题:未审核进公开列表、旧回复覆盖、批量删除恢复
android·mysql·php·工程实践·fengcms
洞见前行2 天前
Android 架构演进全解:从 MVC、MVP、MVVM 到 MVI 的原理、代码实战与得失权衡
android·架构·kotlin
专注Android黑科技2 天前
Android 玩机黑科技:刀盾「系统冰点还原」与「保环境双清(恢复出厂不掉ROOT)」全图解教程
android·技术分享
StarsGreen2 天前
Android meminfo 服务详细介绍
android
三少爷的鞋2 天前
Main-safe、非阻塞与结构化并发,才是协程架构的核心
android