GithubHelp home page GithubHelp logo

支持指定宽高压缩吗? about tiny HOT 16 CLOSED

sunzxyong avatar sunzxyong commented on August 24, 2024
支持指定宽高压缩吗?

from tiny.

Comments (16)

Sunzxyong avatar Sunzxyong commented on August 24, 2024

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

from tiny.

jayleco avatar jayleco commented on August 24, 2024

@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.

jayleco avatar jayleco commented on August 24, 2024

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

from tiny.

Sunzxyong avatar Sunzxyong commented on August 24, 2024

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

from tiny.

jayleco avatar jayleco commented on August 24, 2024

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

from tiny.

jayleco avatar jayleco commented on August 24, 2024

@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.

Sunzxyong avatar Sunzxyong commented on August 24, 2024

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

from tiny.

jayleco avatar jayleco commented on August 24, 2024

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

from tiny.

Sunzxyong avatar Sunzxyong commented on August 24, 2024

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

from tiny.

jayleco avatar jayleco commented on August 24, 2024

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

from tiny.

jayleco avatar jayleco commented on August 24, 2024

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

from tiny.

Sunzxyong avatar Sunzxyong commented on August 24, 2024

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

from tiny.

Sunzxyong avatar Sunzxyong commented on August 24, 2024

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

from tiny.

jayleco avatar jayleco commented on August 24, 2024

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

from tiny.

Sunzxyong avatar Sunzxyong commented on August 24, 2024

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

from tiny.

jayleco avatar jayleco commented on August 24, 2024

谢谢

from tiny.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.