Comments (16)
可以,options中有宽高参数设置
from tiny.
@Sunzxyong 请教下是这样设置的吗?我感觉这么设置这个宽高好像并没有达到需求
Tiny.FileCompressOptions options = new Tiny.FileCompressOptions();
if (imgWidth > screenWidth) {
options.width = screenWidth;
options.height = height;
}
Tiny.getInstance().source(resource).asFile().withOptions(options).compress(new FileCallback() {
@Override
public void callback(boolean isSuccess, String outfile) {
//return the compressed file path
Logger.e("压缩后的地址:" + outfile);
subsamplingScaleImageView.setImage(ImageSource.uri(outfile), new ImageViewState(1.0f, new PointF(0, 0), 0));
}
});
from tiny.
@Sunzxyong 老师能不能给指点下我的错误啊,新手感激……
from tiny.
@jayleco 指定宽高是有效的,详情可以参考Demo。对于你的imgWidth > screenWidth是多于的操作,不需要这样判断,Tiny内部已经做了处理,你只需传入指定的宽高即可,压缩后你可以看输出的outfile信息
from tiny.
我看了下你的中文说明,好像只有bitmap才是根据屏幕动态适配,file是没有动态适配的吧
from tiny.
@Sunzxyong 老师,下面是使用Tiny.BitmapCompressOptions没有做任何配置,我的测试手机屏幕是720,需要压缩的图片原始尺寸为540*5678; 经过下面压缩后图片宽度变为了122px
Tiny.BitmapCompressOptions options = new Tiny.BitmapCompressOptions();
Tiny.getInstance().source(resource).asBitmap().withOptions(options).compress(new BitmapCallback() {
@Override
public void callback(boolean isSuccess, Bitmap bitmap) {
//return the compressed bitmap object
Logger.e("压缩后的宽度:" + bitmap.getWidth());
Logger.e("压缩后图片大小:" + ToolUtils.formatFileSize(bitmap.getByteCount()));
subsamplingScaleImageView.setImage(ImageSource.bitmap(bitmap),new ImageViewState(1.0f, new PointF(0, 0), 0));
}
});
from tiny.
是的,高度为1280。file 也有,是根据1280为基线压缩
from tiny.
@Sunzxyong 那也就是说我如果想让他压缩到适合我屏幕宽度720的话就必须要指定options宽度等于屏幕宽度才可以是吗?
高度是自动根据指定的宽度自适应的还是必须要自己计算然后给options高度?
from tiny.
如果里只想让图片保证在最适合当前屏幕显示的效果,tiny 已经做了,不需要再另外设置
from tiny.
可是我这里不是说了吗?默认什么不做会将这个尺寸的图片宽度压缩成122px,根本没法看了
from tiny.
图片原始尺寸为5405678,如果指定将他等比压缩为72075701;使用tiny指定width、height无效
from tiny.
你这是图片放大,那为何要压缩?
from tiny.
放大你可以适用矩阵,对于你的场景应该是长图显示,不压缩,建议直接显示那么大图片可以适用分块按需解码
from tiny.
@Sunzxyong 是的我使用了subsampling-scale-image-view来显示大图,那请教下作者如何在不改变宽高的情况下对图片大小的压缩呢?比如图片宽高是540*5678;大小为7mb,如何在保持宽高的情况下使体积更小呢?
from tiny.
内存占用更小可以使用RGB_565,file更小则设置压缩的quality
from tiny.
谢谢
from tiny.
Related Issues (20)
- Android6.0 压缩失败 open failed: ENOENT (No such file or directory) HOT 1
- 拍照的图片压缩失败 HOT 3
- Android Q生成file适配问题 HOT 1
- android Q适配 HOT 3
- 我是个小白,谁能给个使用的demo?
- 图片文件压缩,options 设置了压缩后大小,但 7M 的原图压缩后还有 800k+
- lamda表达式混淆崩溃AbstractMethodError HOT 1
- 在微信点击保存图片,然后用tiny来压缩该图片,不会压缩,还是显示原图 HOT 1
- Support ABI x86_64
- 设置options.outfile 没用 HOT 3
- java.lang.UnsatisfiedLinkError HOT 1
- X509TrustManager的问题 HOT 4
- Uri批量压缩失败,单个Uri压缩也失败。
- 这个使用限定语言吗?是在什么场景下使用, 可以用在服务端吗?
- TrustManager
- Why it need this project network connection?
- X509TrustManager Vulnerability warning from Google Play HOT 1
- Error Apache Trust Manager - implementation of the X509TrustManager HOT 1
- 视频压缩失败
- [Security] libjpeg-turbo used in this project is vulnerable
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tiny.