Copyright: Zhang Phil Reprint please indicate the source: http://blog.csdn.net/zhangphil
Android Glide to load the picture into round, rounded corners, frosted glass and other picture effects
Appendix 1 gives a brief introduction to the Android open source image loading framework. In the real world, although Glide solved the problem of loading images quickly, one problem remained unsolved: Such as the head of the user, often the head of the user to read from the server an ordinary rectangular images, but now the design of the general requirements avatars displayed on the APP end into a rounded head, so although Glide can be loaded at this time, but is a rectangular load, if you want to Glide in the process of loading the rectangle into a round, Glide – blah blah blah blah blah blah blah… Write an example to illustrate.
package zhangphil.app; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.widget.ImageView; import com.bumptech.glide.Glide; import jp.wasabeef.glide.transformations.BlurTransformation; import jp.wasabeef.glide.transformations.CropCircleTransformation; import jp.wasabeef.glide.transformations.RoundedCornersTransformation; Public class MainActivity extends AppCompatActivity {// I CSDN blog avatar String URL = "http://avatar.csdn.net/9/7/A/1_zhangphil.jpg"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ImageView image1 = (ImageView) findViewById(R.id.image1); Glide.with(this).load(url).crossFade(1000).into(image1); ImageView image2 = (ImageView) findViewById(r.id.image2); Glide.with(this).load(url).bitmapTransform(new CropCircleTransformation(this)).crossFade(1000).into(image2); ImageView image3 = (ImageView) findViewById(R.i.image3); Glide.with(this).load(url).bitmapTransform(new BlurTransformation(this, 25)).crossFade(1000).into(image3); ImageView image4 = (ImageView) findViewById(R.i.image4); Glide.with(this).load(url).bitmapTransform(new BlurTransformation(this, 25), new CropCircleTransformation(this)).crossFade(1000).into(image4); // The original image is rounded, If it is ALL around is rounded corners is RoundedCornersTransformation CornerType. ALL ImageView image5 = (ImageView) the findViewById (R.i d.i mage5); Glide.with(this).load(url).bitmapTransform(new RoundedCornersTransformation(this, 30, 0, RoundedCornersTransformation.CornerType.BOTTOM)).crossFade(1000).into(image5); }}Copy the code
The layout is simpler, a linear vertical layout with five ImageViews.
Code run results.
Appendix:
1, the Android images load and cache open source framework: Android Glide “links: blog.csdn.net/zhangphil/a…
- Guess you are looking for