Crop square image to circle - Programmatically

前端 未结 7 1405
余生分开走
余生分开走 2020-12-01 01:14

i was searching for past one day and i was not successful .

i get the image from API , and i download it to a bitmap file using the following code .

         


        
相关标签:
7条回答
  • 2020-12-01 01:52

    Once the bitmap is retrieved RoundedBitmapDrawableFactory can be used to generate a RoundedBitmapDrawable from the v4 Support Library. That Drawable can then be applied to an ImageView or directly drawn to a Canvas.

    // Create the RoundedBitmapDrawable.
    RoundedBitmapDrawable roundDrawable = RoundedBitmapDrawableFactory.create(getResources(), bitmap);
    roundDrawable.setCircular(true);
    
    // Apply it to an ImageView.
    ImageView imageView = (ImageView)findViewById(R.id.imageView);
    imageView.setImageDrawable(roundDrawable);
    
    // Alternatively, draw it to an canvas (e.g. in onDraw where a Canvas is available).
    // setBounds since there's no View handling size and positioning.
    roundDrawable.setBounds(left, top, right, bottom);
    roundDrawable.draw(canvas);
    
    0 讨论(0)
提交回复
热议问题