Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

支持指定宽高压缩吗? #14

Closed
jayleco opened this issue May 7, 2017 · 16 comments
Closed

支持指定宽高压缩吗? #14

jayleco opened this issue May 7, 2017 · 16 comments

Comments

@jayleco
Copy link

jayleco commented May 7, 2017

比如设置图片为屏幕宽度进行比例压缩,或指定宽高在进行压缩

@Sunzxyong
Copy link
Owner

可以,options中有宽高参数设置

@jayleco
Copy link
Author

jayleco commented May 7, 2017

@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));
                        }
                    });

@jayleco
Copy link
Author

jayleco commented May 8, 2017

@Sunzxyong 老师能不能给指点下我的错误啊,新手感激……

@Sunzxyong
Copy link
Owner

@jayleco 指定宽高是有效的,详情可以参考Demo。对于你的imgWidth > screenWidth是多于的操作,不需要这样判断,Tiny内部已经做了处理,你只需传入指定的宽高即可,压缩后你可以看输出的outfile信息

@jayleco
Copy link
Author

jayleco commented May 8, 2017

我看了下你的中文说明,好像只有bitmap才是根据屏幕动态适配,file是没有动态适配的吧

@jayleco
Copy link
Author

jayleco commented May 8, 2017

@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));
                        }
                    });

@Sunzxyong
Copy link
Owner

是的,高度为1280。file 也有,是根据1280为基线压缩

@jayleco
Copy link
Author

jayleco commented May 9, 2017

@Sunzxyong 那也就是说我如果想让他压缩到适合我屏幕宽度720的话就必须要指定options宽度等于屏幕宽度才可以是吗?
高度是自动根据指定的宽度自适应的还是必须要自己计算然后给options高度?

@Sunzxyong
Copy link
Owner

如果里只想让图片保证在最适合当前屏幕显示的效果,tiny 已经做了,不需要再另外设置

@jayleco
Copy link
Author

jayleco commented May 10, 2017

可是我这里不是说了吗?默认什么不做会将这个尺寸的图片宽度压缩成122px,根本没法看了

@jayleco
Copy link
Author

jayleco commented May 10, 2017

图片原始尺寸为5405678,如果指定将他等比压缩为72075701;使用tiny指定width、height无效

@Sunzxyong
Copy link
Owner

你这是图片放大,那为何要压缩?

@Sunzxyong
Copy link
Owner

Sunzxyong commented May 11, 2017

放大你可以适用矩阵,对于你的场景应该是长图显示,不压缩,建议直接显示那么大图片可以适用分块按需解码

@jayleco
Copy link
Author

jayleco commented May 11, 2017

@Sunzxyong 是的我使用了subsampling-scale-image-view来显示大图,那请教下作者如何在不改变宽高的情况下对图片大小的压缩呢?比如图片宽高是540*5678;大小为7mb,如何在保持宽高的情况下使体积更小呢?

@Sunzxyong
Copy link
Owner

内存占用更小可以使用RGB_565,file更小则设置压缩的quality

@jayleco
Copy link
Author

jayleco commented May 11, 2017

谢谢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants