简体   繁体   English

如何在Android中使用壁画设置渐进式JPEG

[英]How to set up progressive jpegs using fresco in android

I have just started using fresco and I have followed the steps in their documentation. 我刚刚开始使用壁画,并且已经按照其文档中的步骤进行操作。 I have been able to load URIs into the SimpleDraweeView within my listview adapter and now I am trying to implement progressive jpegs(images increase in quality as they load). 我已经能够将URI加载到列表视图适配器中的SimpleDraweeView中,现在我正在尝试实现渐进式jpeg(图像在加载时质量会提高)。 The problem is that the code they have given in the site is not working as expected. 问题是他们在站点中提供的代码无法正常工作。 The Uri is being loaded, but not progressively(The image is not gradually increasing in quality as it loads). Uri正在加载,但不是逐步加载(加载时图像的质量没有逐渐提高)。 Is there something I am missing or have forgotten to add? 有什么我想念的东西或忘记添加的吗?

Here is my build dependency: 这是我的构建依赖项:

compile 'com.facebook.fresco:fresco:0.13.+'

I have already added this in my application class: 我已经在我的应用程序类中添加了它:

//For fresco
 Fresco.initialize(this);

Here is my xml 这是我的xml

<com.facebook.drawee.view.SimpleDraweeView
                android:id="@+id/tag_iv_tu"
                android:layout_width="@dimen/tu_tag_side"
                android:layout_height="@dimen/tu_tag_height"
                android:layout_centerInParent="true"
                android:layout_gravity="center_horizontal"
                fresco:placeholderImage="@drawable/abc_ic_menu_share_mtrl_alpha" />

And here is the code within the getView() method in my listview adapter 这是我的列表视图适配器中getView()方法中的代码

ImageRequest request = ImageRequestBuilder.newBuilderWithSource(fileUri)
                            .setProgressiveRenderingEnabled(true)
                            .build();
                    DraweeController controller = Fresco.newDraweeControllerBuilder()
                            .setImageRequest(request)
                            .setOldController(holder.tag_iv_tu.getController())
                            .build();
                    holder.tag_iv_tu.setController(controller);

You must set the ResizeOption for the ImageRequst,because the progressily depends on ResizeOptions. 您必须为ImageRequst设置ResizeOption,因为进度取决于ResizeOptions。

Try this: 尝试这个:

ResizeOptions options = new ResizeOptions(width, height);

ImageRequest request = ImageRequestBuilder
            .newBuilderWithSource(Uri.parse(uri))
            .setProgressiveRenderingEnabled(true).setResizeOptions(options)
            .build();

Use this code : 使用此代码:

        String url ="http://...";
        Uri uri = Uri.parse(url);

        ImageRequest request = ImageRequestBuilder.newBuilderWithSource(uri)
                .setProgressiveRenderingEnabled(true)
                .build();

        DraweeController controller = Fresco.newDraweeControllerBuilder()
                .setImageRequest(request)
                .setOldController(image.getController())
                .build();

        mSimpleDraweeView.setController(controller);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM