Glide图片大小调整 & 缩放
resize(x, y)调整图片大小
1、理想情况下,你的服务器或者API能够返回给你恰好所需分辨率的图片,这是在网络带宽、内存消耗和图片质量下的完美方案。
2、跟Picasso比起来,Glide在内存上占用更优化。Glide在缓存和内存里自动限制图片的大小去适配ImageView的尺寸。Picasso也有同样的能力,但需要调用fit()方法。用Glide时,如果图片不需要自动适配ImageView,调用override(horizontalSize, verticalSize),它会在将图片显示在ImageView之前调整图片的大小。
3、Glide .with(context) .盟敢势袂load(UsageExampleListViewAdapter.eatF泠贾高框oodyImages[0]) .override(600, 200) // resizes the image to these dimensions (in pixel). does not respect aspect ratio .into(imageViewResize);这个设置可能也是有利于没有明确目标,但已知尺寸的视图上。例如,如果app想要预先缓存在splash屏幕上,还没法测量出ImageVIews具体宽高。但,如果你已经知道图片应当为多大,使用override可以提供一个指定的大小的图片。
缩放图片
1、现在,对于任何图像的任何处理,调整图像的大小可能会扭曲长宽比,丑化图片的显示。在大多数情况下,你希望防止这种事情发升。Glide提供了变换去处理图片显示,通过设置centerCr泠贾高框op 和 fitCenter,可以得到两个不同的效果。CenterCropCenterCrop()会缩放图片让图片充满整个ImageView的边框,然后裁掉超出的部分。ImageVIew会被完全填充满,但是图片可能不能完全显示出。Glide .with(context) .load(UsageExampleListViewAdapter.eatFoodyImages[0]) .override(600, 200) // resizes the image to these dimensions (in pixel) .centerCrop() // this cropping technique scales the image so that it fills the requested bounds and then crops the extra. .into(imageViewResizeCenterCrop);
2、FitCenterfitCenter()会缩放图片让两边都相等或小于ImageView的所需求的边框。图片会被完整显示,可能不能完全填充整个ImageView。Glide .with(context) .load(UsageExampleListViewAdapter.eatFoodyImages[0]) .override(600, 200) .fitCenter() .into(imageViewResizeFitCenter);