Code Monkey home page Code Monkey logo

Comments (3)

philadelphia avatar philadelphia commented on September 20, 2024

sorry for my english and hope u can understand

from litho.

colriot avatar colriot commented on September 20, 2024

Hi @philadelphia ! Can you please share a code that uses FrescoImage and screenshots of the wrong UI with images?

from litho.

philadelphia avatar philadelphia commented on September 20, 2024

Now i use FrescoImage to load a network image resource (i use uri of a local image in this demo) when i set cornerRadius and FrescoImage's scaleType to any type except CENTER_CROP,FIT_XY,FOCUS_CROP, and i get something wrong .if i remove cornerRadius and everything is OK . I have noticed the comment of RoundingParams.BITMAP_ONLY
as the default roundingMethod.But i wanna get these two features together(radius and other scaleType eg: CenterInside).how to do?

截屏2021-07-20 下午7 53 19

截屏2021-07-20 下午7 53 52

ic_tomcat

   package com.example.lithodemo.ui;
    
    import android.content.Context;
    import android.net.Uri;
    import android.os.Bundle;
    
    import androidx.annotation.Nullable;
    import androidx.appcompat.app.AppCompatActivity;
    
    import com.example.lithodemo.databinding.ActivityMainBinding;
    import com.facebook.drawee.backends.pipeline.DraweeConfig;
    import com.facebook.drawee.backends.pipeline.Fresco;
    import com.facebook.drawee.drawable.ScalingUtils;
    import com.facebook.drawee.generic.RoundingParams;
    import com.facebook.imagepipeline.core.ImagePipelineConfig;
    import com.facebook.litho.ComponentContext;
    import com.facebook.litho.LithoView;
    import com.facebook.litho.fresco.FrescoImage;
    
    public class MainActivity extends AppCompatActivity {
        private static final String RESOURCE_PATH_DRAWABLE = "drawable";
        private static final String RESOURCE_PATH_MIPMAP = "mipmap";
        private static final String RESOURCE_PATH_RAW = "raw";
    
        @Override
        public void onCreate(@Nullable Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            ActivityMainBinding binding = ActivityMainBinding.inflate(getLayoutInflater());
            setContentView(binding.getRoot());
            ComponentContext componentContext = new ComponentContext(this);
            ImagePipelineConfig imagePipelineConfig = ImagePipelineConfig.newBuilder(this).build();
            DraweeConfig draweeConfig = DraweeConfig.newBuilder()
                    .build();
            Fresco.initialize(this, imagePipelineConfig, draweeConfig);
    
            int resId = getResourceId(componentContext.getAndroidContext(), "ic_tomcat");
            String uri = Uri.parse("res://" + componentContext.getAndroidContext().getPackageName() + "/" + resId).toString();
            FrescoImage.Builder builder = FrescoImage.create(componentContext)
                    .widthDip(100)
                    .heightDip(100)
                    .controller(Fresco.newDraweeControllerBuilder().setUri(uri).build());
            builder.actualImageScaleType(ScalingUtils.ScaleType.CENTER_INSIDE);
    
            RoundingParams roundingParams = new RoundingParams();
            roundingParams.setCornersRadius(40);
            builder.roundingParams(roundingParams);
    
            LithoView lithoView = LithoView.create(componentContext, builder.build());
            binding.llViewGroup1.addView(lithoView);
    
            FrescoImage.Builder builder2 = FrescoImage.create(componentContext)
                    .widthDip(100)
                    .heightDip(100)
                    .controller(Fresco.newDraweeControllerBuilder().setUri(uri).build());
            builder2.actualImageScaleType(ScalingUtils.ScaleType.CENTER_INSIDE);
            RoundingParams roundingParams2 = new RoundingParams();
            builder2.roundingParams(roundingParams2);
            LithoView lithoView2 = LithoView.create(componentContext, builder2.build());
            binding.llViewGroup2.addView(lithoView2);
    
        }
    
        /**
         * get resource id by resource name
         *
         * @param context
         * @param resName
         * @return resId
         */
        public int getResourceId(Context context, String resName) {
            int resId = context.getResources().getIdentifier(resName, RESOURCE_PATH_DRAWABLE, context.getPackageName());
            if (resId == 0) {
                resId = context.getResources().getIdentifier(resName, RESOURCE_PATH_MIPMAP, context.getPackageName());
            }
            if (resId == 0) {
                resId = context.getResources().getIdentifier(resName, RESOURCE_PATH_RAW, context.getPackageName());
            }
            return resId;
        }
    
    }   

from litho.

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.